• Resolved FilipD

    (@filipd)


    Hello

    I have the following problem:

    I want to change the pagination for my calendar.
    I know where to change it in the plugin folder (em-functions.php) and when I change it, it works. However, this is not the proper way to do it because then every update of EM will override the changes.

    So I’ve been trying to change it with mu-plugins (this is new for me).
    I’ve made a mu-plugins folder in my wp-content with a em-functions.php file in it.

    The content is:

    <?php
    function em_paginate($link, $total, $limit, $page=1, $pagesToShow=10){
    	if($limit > 0){
    		$url_parts = explode('?', $link);
    		$base_link = $url_parts[0];
        	//Get querystring for first page without page
        	$query_arr = array();
        	parse_str($url_parts[1], $query_arr);
        	unset($query_arr['page']); unset($query_arr['pno']);
        	$base_querystring = build_query($query_arr);
        	if( !empty($base_querystring) ) $base_querystring = '?'.$base_querystring;
        	//calculate
    		$maxPages = ceil($total/$limit); //Total number of pages
    		$startPage = ($page <= $pagesToShow) ? 1 : $pagesToShow * (floor($page/$pagesToShow)) ; //Which page to start the pagination links from (in case we're on say page 12 and $pagesToShow is 10 pages)
    		$placeholder = urlencode('%PAGE%');
    		$link = str_replace('%PAGE%', $placeholder, $link); //To avoid url encoded/non encoded placeholders
    	    //Add the back and first buttons
    		    $string = '<div class="navigation">';
    		    $string .= ($page>1 && $startPage != 1) ? '<a class="prev page-numbers" href="'.str_replace($placeholder,1,$link).'" title="1">1</a> ' : '';
    		    if($page == 2){
    		    	$string .= ' <a class="prev page-numbers" href="'.$base_link.$base_querystring.'" title="2">&laquo;</a> ';
    		    }elseif($page > 2){
    		    	$string .= ' <a class="prev page-numbers" href="'.str_replace($placeholder,$page-1,$link).'" title="'.($page-1).'">&laquo;</a> ';
    		    }
    		//Loop each page and create a link or just a bold number if its the current page
    		    for ($i = $startPage ; $i < $startPage+$pagesToShow && $i <= $maxPages ; $i++){
    	            if($i == $page){
    	                $string .= ' <strong><span class="page-numbers current">'.$i.'</span></strong>';
    	            }elseif($i=='1'){
    	                $string .= ' <a class="page-numbers" href="'.$base_link.$base_querystring.'" title="'.$i.'">'.$i.'</a> ';
    	            }else{
    	                $string .= ' <a class="page-numbers" href="'.str_replace($placeholder,$i,$link).'" title="'.$i.'">'.$i.'</a> ';
    	            }
    		    }
    		//Add the forward and last buttons
    		    $string .= ($page < $maxPages) ? ' <a class="next page-numbers" href="'.str_replace($placeholder,$page+1,$link).'" title="'.($page+1).'">&raquo;</a> ' :' ' ;
    		    $string .= ($i-1 < $maxPages) ? ' <a class="next page-numbers" href="'.str_replace($placeholder,$maxPages,$link).'" title="'.$maxPages.'">'.$maxPages.'</a> ' : ' ';
    		   $string .= '</div>';
    		//Return the string
    		    return apply_filters('em_paginate', $string);
    	}
    
    }
    ?>

    Doing this, removes the pagination all together, allthough the functions seems to be read (if I put “echo ‘hello world’;” in it, it shows hello world).

    Can somebody help me please?
    Thx!

    http://ww.wp.xz.cn/extend/plugins/events-manager/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support angelo_nwl

    (@angelo_nwl)

    can I know what changes do you want?

    Thread Starter FilipD

    (@filipd)

    I have WP-paginate for all my pagination and I want to make the EM pagination look similar. Therefor I don’t want ‘>’ and ”>>’ but ‘»’ and the last page number.

    1 2 3 » 11
    instead of
    1 2 3 > >>

    Plugin Support angelo_nwl

    (@angelo_nwl)

    try this snippet – http://pastebin.com/NvTfBJYu

    *paste in your theme functions.php

    Thread Starter FilipD

    (@filipd)

    Thx Angelo!

    But unfortunately it isn’t going to work that way, i’m afraid.

    For example:

    this is what I want to have:

    $string = '<div class="navigation">';
    		    $string .= ($page>1 && $startPage != 1) ? '<a class="prev page-numbers" href="'.str_replace($placeholder,1,$link).'" title="1"><strong>1</strong></a> ' : '';
    		    if($page == 2){
    		    	$string .= ' <a class="prev page-numbers" href="'.$base_link.$base_querystring.'" title="2">«</a> ';
    		    }elseif($page > 2){
    		    	$string .= ' <a class="prev page-numbers" href="'.str_replace($placeholder,$page-1,$link).'" title="'.($page-1).'">«</a> ';
    		    }

    This is what it normally is:

    $string .= ' <strong><span class="page-numbers current">'.$i.'</span></strong>';
    }elseif($i=='1'){
    $string .= ' <a class="page-numbers" href="'.$base_link.$base_querystring.'">'.$i.'</a> ';
    }else{
    $string .= ' <a class="page-numbers" href="'.str_replace($placeholder,$i,$link).'">'.$i.'</a> ';
    }

    Too much stuff to string replace.

    So I was wondering if I could change the function in a different way than to add a filter in functions.php (+ that I don’t always have to change the code again, if I update the plugin).

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    not sure if it’d work in your functions.php but if you created a file in the wp-content/mu-plugins folder then it’d work.

    you can override the em_paginate function by copy/pasting and editing there.

    Thread Starter FilipD

    (@filipd)

    Strange. tried it again with mu-plugins and it works.

    Thx for the help guys.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    glad it’s working now.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Changing the pagination’ is closed to new replies.