• Hello all,

    I am using a function to show Google-style pagination (<<1,2,3>>) instead of the standard “Previous/Next” using a script I found online. It’s working great except I am getting a strange error every once-in-awhile when running it. Here’s the PHP which is pasted into function.php:

    <?php function wp_pagenaviNew($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false)
    {
    	global $request, $posts_per_page, $wpdb, $paged;
    	   if(empty($prelabel)) { $prelabel = '<strong><<</strong>';
    	} if(empty($nxtlabel)) {
    
    $nxtlabel = '<strong>>></strong>';
    	} $half_pages_to_show = round($pages_to_show/2);
    	   if (!is_single()) {
    	   if(!is_category()) {
    preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches); } else {
    preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); }
    
    $fromwhere = $matches[1];
    $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
    $max_page = ceil($numposts /$posts_per_page);
    if(empty($paged)) {
    $paged = 1;
    }
    
    if($max_page > 1 || $always_show) {
    echo "$before <div class='Nav'>Pages ($max_page): "; if ($paged >= ($pages_to_show-1)) {
    echo '<a href="'.get_pagenum_link().'"><< First</a>  '; }
    	previous_posts_link($prelabel);
    for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) { if ($i >= 1 && $i <= $max_page) { if($i == $paged) {
    echo "<strong class='on'>$i</strong>";
    } else {
    echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> '; }
    }
    }
    next_posts_link($nxtlabel, $max_page);
    if (($paged+$half_pages_to_show) < ($max_page)) {
    echo '  <a href="'.get_pagenum_link($max_page).'">Last >></a>'; }
    echo "</div> $after";
    }
    }
    }
    ?>

    The error involves something about writing to the header and includes an error to line 850 of pluggable.php which seems to have something to do with the location URL. But, I can’t seem to get the error to happen consistently and it just started occurring when I put this script in. Anyone know what is going on or if it is something with pluggable.php? Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter misterpatrick67

    (@misterpatrick67)

    I had some extra white space between PHP stuff in functions.php which I’ve now stripped out and don’t know of that was contributing to the problem.

Viewing 1 replies (of 1 total)
  • The topic ‘Issue with Google-Style Pagination’ is closed to new replies.