Advertisement
Guest User

Events Manager Pagination

a guest
Aug 15th, 2013
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. function my_em_paginate($links, $link, $total, $limit, $page=1, $pagesToShow=10)
  2. {
  3.     if ($limit > 0)
  4.     {
  5.         $url_parts = explode('?', $link);
  6.         $base_link = $url_parts[0];
  7.                
  8.                 //Get querystring for first page without page
  9.                 $query_arr = array();
  10.                 parse_str($url_parts[1], $query_arr);
  11.                 unset($query_arr['page']); unset($query_arr['pno']);
  12.                 $base_querystring = build_query($query_arr);
  13.                 if( !empty($base_querystring) ) $base_querystring = '?'.$base_querystring;
  14.                
  15.                 //calculate
  16.         $maxPages = ceil($total/$limit); //Total number of pages
  17.  
  18.         $placeholder = urlencode('%PAGE%');
  19.         $link = str_replace('%PAGE%', $placeholder, $link); //To avoid url encoded/non encoded placeholders
  20.            
  21.         $string = '<div id="paginator"><div id="paginator_left"></div>';
  22.         $string .= '<div id="paginator_mid">';
  23.  
  24.         $string .= '<span id="prev">';
  25.         if ($page > 1)
  26.         {
  27.             $string .= '<a href="'.str_replace($placeholder,$page-1,$link).'" title="Previous"> </a>'; 
  28.         }
  29.         $string .= '</span>';
  30.        
  31.         $string .= '<span id="next">';
  32.         if ($page < $maxPages)
  33.         {
  34.             $string .= '<a href="'.str_replace($placeholder,$page+1,$link).'" title="Next"> </a>'; 
  35.         }
  36.         $string .= '</span>';
  37.        
  38.         $string .= '</div>';
  39.         $string .= '<div id="paginator_right"></div></div>';
  40.        
  41.         //Return the string
  42.         return apply_filters('em_paginate', $string);
  43.     }
  44. }
  45. add_filter('em_events_output_pagination','my_em_paginate', 1, 6);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement