Skip to main content

Get Google Calendar Event List in WordPress

<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function  get_calender_events() { $params = array(); /*Get current date*/ $current_date  = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key =  "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url,

Smarty Pagination with php mysql

Smarty Pagination with php mysql
-------------------------------------------------------------
--------------------------------------------------------------
 <?php
 Pagination using PHP,Smarty And MySql
$sql="SELECT * FROM `fieldname1` WHERE is_active='Y' ORDER BY fieldmame2";
$rs=mysql_query($sql);
$num=mysql_num_rows($rs);
$i=0;
/*while ($row = mysql_fetch_array($rs)) {
$arr1[$j] = $row;
$j++;
}*/
////////////////////////////////////////////
if (!(isset($pagenum)))
{
$pagenum = 1;
}

//Here we count the number of results
//Edit $data to be your query

$rows = $num;

//This is the number of results displayed per page
$page_rows = 2;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

//This sets the range to display in our query
$max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;

$SqlQuery=$sql." LIMIT ". ($pagenum - 1) * $page_rows.",$page_rows";
$data_p=mysql_query($SqlQuery);

////////////////////////////////////////////
while($row1 = mysql_fetch_array($data_p)) {
$arr[$i] = $row1;
$i++;
}
if ($pagenum == 1)
{
}
else
{
$previous = $pagenum-1;
}
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;

}
$smarty->assign("arr",$arr);
$smarty->assign("pagenum",$pagenum);
$smarty->assign("previous",$previous);
$smarty->assign("last",$last);
$smarty->assign("next",$next);
?>
-------------------------------------------------------
-------------------------------------------------------
Example:
////////////
//search.php
////////////
function get_db_results()
  {
      $id = $_GET['id'];
      if (preg_match('#[^A-Za-z0-9]#', $id)) {
          echo "<center><font style=\"font-family:tahoma;\">...should be between 4 and 40 letters and numbers only. <a href=\"javascript:history.go(-1)\">Go Back</a></center>";
          die();
      }
      if (strlen($id) < 4) {
          echo "<center><font style=\"font-family:tahoma;\">Field must be at least 4 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
          die();
      }
      if (strlen($id) > 40) {
          echo "<center><font style=\"font-family:tahoma;\">Field Max Characters: 40
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
          die();
      }
      $_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM links WHERE linkname LIKE '%%$id%%' LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
      $_result = mysql_query($_query);
      while ($_row = mysql_fetch_array($_result, MYSQL_ASSOC)) {
          $_data[] = $_row;
      }
      $_query = "SELECT FOUND_ROWS() as total";
      $_result = mysql_query($_query);
      $_row = mysql_fetch_array($_result, MYSQL_ASSOC);
      SmartyPaginate::setTotal($_row['total']);
      mysql_free_result($_result);
      return @$_data;
  }

require ('libs/SmartyPaginate.class.php');
SmartyPaginate::connect();
SmartyPaginate::setLimit(10);
SmartyPaginate::setUrl('search.php');

$smarty->assign('results', get_db_results());
SmartyPaginate::assign($smarty);
$smarty->display('search.php');


//////////////////////
//search.php(template)
//////////////////////



{section name="results" loop=$results}
{$results[results].linkname}<br />
{/section}

Links {$paginate.first}-{$paginate.last} of {$paginate.total}.
{paginate_prev} {paginate_next}



Comments

Popular posts from this blog

Create post with all post type

<?php /* add_action( 'wp_enqueue_scripts', 'mpcth_child_enqueue_scripts', 1000 ); function mpcth_child_enqueue_scripts() { wp_enqueue_style( 'mpc-styles-child', get_stylesheet_directory_uri() . '/style_custom.css' ); } */ function registration_form( $username, $fname, $lname, $email, $password, $confirm_password, $account_type, $distict_city, $school_name ,$school_address, $school_type, $grade_level, $invcode ) { ?>     <style>       /* Always set the map height explicitly to define the size of the div        * element that contains the map. */     #map {     height: 260px; }     </style>   <script> function initMap() {     var map = new google.maps.Map(document.getElementById('map'), {       center: {lat: -33.8688, lng: 151.2195},       zoom: 13     });     var input = document.getElementById('searchInput');    // map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);    

Create Signature pad with save on database in php

Create Signature pad with save on database in php 1.create a folder images index.php ============   <!DOCTYPE >     <head>     <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />     <title>Signature Pad</title>     <script type="text/javascript" src="jquery-1.8.0.min.js"></script>     <script type="text/javascript"> $(document).ready(function () {     /** Set Canvas Size **/     var canvasWidth = 400;     var canvasHeight = 100;     /** IE SUPPORT **/     var canvasDiv = document.getElementById('signaturePad');     canvas = document.createElement('canvas');     canvas.setAttribute('width', canvasWidth);     canvas.setAttribute('height', canvasHeight);     canvas.setAttribute('id', 'canvas');     canvasDiv.appendChild(canvas);     if (typeof G_vmlCanvasManager != 'undefined') {