0

My main blog page, and search keyword and category filter pages all pull in the same loop-blog-grid.php template, therefore all pull in <?php themeple_pagination(); ?>.

The issue I'm having is baffling me. When on the main blog page, the pagination does not display the posts of the page it should, but shows that it should with the URL change. For example, when on the first page of posts, clicking to page 2 changes the URL structure to /page/2, but merely refreshes the display of page 1's posts.

However, if I were to filter the posts or search by keyword, both pages pull in the same loop-blog-grid.php template, but don't give me an error when flipping between pages.

Any ideas about what's causing this?

pagination function:

function themeple_pagination(){

      if( is_singular() )
    return;

  global $wp_query;

  /** Stop execution if there's only 1 page */
  if( $wp_query->max_num_pages <= 1 )
    return;

  $paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' )  : 1;
  $max   = intval( $wp_query->max_num_pages );

  /** Add current page to the array */
  if ( $paged >= 1 )
    $links[] = $paged;

  /** Add the pages around the current page to the array */
  if ( $paged >= 3 ) {
    $links[] = $paged - 1;
    $links[] = $paged - 2;
  }

  if ( ( $paged + 2 ) <= $max ) {
    $links[] = $paged + 2;
    $links[] = $paged + 1;
  }

  echo '<div class="pagi"><ul>' . "\n";



  /** Link to first page, plus ellipses if necessary */
  if ( ! in_array( 1, $links ) ) {
    $class = 1 == $paged ? ' class="selected"' : '';

    printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );

    if ( ! in_array( 2, $links ) )
      echo '<li>…</li>';
  }

  /** Link to current page, plus 2 pages in either direction if necessary */
  sort( $links );
  foreach ( (array) $links as $link ) {
    $class = $paged == $link ? ' class="selected"' : '';
    printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
  }

  /** Link to last page, plus ellipses if necessary */
  if ( ! in_array( $max, $links ) ) {
    if ( ! in_array( $max - 1, $links ) )
      echo '<li>… &nbsp;</li>' . "\n";

    $class = $paged == $max ? ' class="selected"' : '';
    printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
  }

  echo '</ul></div>' . "\n";

}

loop-blog-grid (with themeple_pagination() call at end):

<?php
global $themeple_config;
do_action('themeple_excecute_query_var_action','loop-index');
$avatar_bool = themeple_get_option('avatar_bool');
if(isset($_COOKIE['authimg']) && !empty($_COOKIE['authimg']) )
    $avatar_bool = $_COOKIE['authimg'];
if (have_posts()) :
    $i = 0;
    while (have_posts()) : the_post();
        $grid_blog_columns = themeple_get_option('grid_blog_columns');
        if(isset($_COOKIE['masonry_cols']) && !empty($_COOKIE['masonry_cols']) )
            $grid_blog_columns = $_COOKIE['masonry_cols'];
        $i++;
        if( ($i % $grid_blog_columns) == 1 && $i != 1){
            echo '</div>';
            echo '<div class="row-fluid grid_row">';
        }
        if($i == 1){
            echo '<div class="row-fluid grid_row">';
        }
        $post_id    = get_the_ID();
        $title      = get_the_title();
        $content    = get_the_content();
        $content    = str_replace(']]>', ']]&gt;', apply_filters('the_content', $content ));
        $post_format = get_post_format($post_id);
        if(strlen($post_format) == 0)
            $post_format = 'standart';
        $count = 0;
        $comment_entries = get_comments(array( 'type'=> 'comment', 'post_id' => $post->ID ));
        if(count($comment_entries) > 0){
            foreach($comment_entries as $comment){
                if($comment->comment_approved)
                    $count++;
            }
        }
        $item_grid_class = 4;
        switch($grid_blog_columns){
            case "1": $item_grid_class = 12; break;
            case "2": $item_grid_class = 6; break;
            case "3": $item_grid_class = 4; break;
            case "4": $item_grid_class = 3; break;
        }
        ?>

        <?php
        if($wp_query->found_posts == $i)

            echo '</div>';
    endwhile; ?>

    <div class="p_pagination">


        <?php themeple_pagination(); ?>

    </div>
<?php endif;

?>

template-blog.php (main blog page template)

<?php

global $themeple_config;
$themeple_config['multi_entry_page'] = true;
$themeple_config['current_sidebar'] = themeple_get_option('blog_sidebar_position');
$spancontent = 12;

if(isset($_COOKIE['themeple_blog']) && $_COOKIE['themeple_blog'] == 'sidebar' )
    $themeple_config['current_sidebar'] = 'sidebar_right';
    if($themeple_config['current_sidebar'] == 'fullsize')
        $spancontent = 12;
    else
        $spancontent = 9;
    $blog_page = themeple_get_option('blogpage');

$themeple_config['current_view'] = 'blog';
$cookie_blog = 'normal';
$cookie_sidebar = 'fullsize';
if(isset($_COOKIE['themeple_blog']) && $_COOKIE['themeple_blog'] != '')
    $cookie_blog = $_COOKIE['themeple_blog'];
if(isset($_COOKIE['themeple_sidebar']) && $_COOKIE['themeple_sidebar'] != ''){

    $cookie_sidebar = $_COOKIE['themeple_sidebar'];
    if($cookie_sidebar == 'none')
        $spancontent = 12;
}


get_header();

?>
 <?php

            $title = get_the_title();
            $page_parents = page_parents();
            $blog_style = themeple_get_option('blog_style');
            $subtitle = themeple_post_meta(themeple_get_post_id(), 'page_header_desc');
        ?>

    <?php if(themeple_post_meta(themeple_get_post_id(), 'page_header_bool') == 'yes'):
            $extra_class = '';
            $extra_style = '';
            if(themeple_post_meta(themeple_get_post_id(), 'header_type') == 'image'){
                $extra_style .= 'background-image:url('.themeple_post_meta(themeple_get_post_id(), 'background_image').');background-repeat: no-repeat;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover; ';
                $extra_class .= ' background_image';
            }else if(themeple_post_meta(themeple_get_post_id(), 'header_type') == 'color'){
                $extra_class .= ' colored_bg';
                $extra_style .= ' background:'.themeple_post_meta(themeple_get_post_id(), 'color_pick').';';
            }

            if(themeple_post_meta(themeple_get_post_id(), 'page_header_animated') == 'yes'){
                $extra_class .= ' animated_header';
            }
    ?>
    <!-- Page Head -->
    <?php  ?>
   <div class="header_page <?php echo $extra_class ?>" style="<?php echo $extra_style ?>">
             <div class="animated_part"></div>
             <div class="container">
                <div class="row-fluid">
                    <div class="span6">
                        <h2><?php echo $title ?></h2>
                    </div>
                    <div class="breadcrumbss">

                        <ul class="page_parents pull-right">
                            <li><a href="<?php echo home_url() ?>">Home</a></li>

                            <?php for($i = count($page_parents) - 1; $i >= 0; $i-- ){ ?>

                            <li><a href="<?php echo get_permalink($page_parents[$i]) ?>"><?php echo get_the_title($page_parents[$i]) ?> </a></li>

                            <?php }  ?>
                            <li class="active"><a href="<?php echo get_permalink() ?>"><?php echo $title ?></a></li>

                        </ul>
                    </div>
                </div>
            </div>

    </div>


    <?php endif; ?>

<section id="content">
        <div class="container" id="blog">
            <div class="row">
    <?php if(($themeple_config['current_sidebar'] == 'sidebar_left' && !isset($_COOKIE['themeple_sidebar'])) || (isset($_COOKIE['themeple_sidebar']) && $_COOKIE['themeple_sidebar'] == 'left' )) get_sidebar() ?>
        <div class="span<?php echo $spancontent ?>">
    <?php
       ( $blog_style == 'grid' && !isset($_COOKIE['themeple_blog'])) || (isset($_COOKIE['themeple_blog']) && $_COOKIE['themeple_blog'] == 'grid' ){

            get_template_part( 'template_inc/loop', 'blog-grid' );


    ?>

        </div>
<?php
    wp_reset_query();

    if(($themeple_config['current_sidebar'] == 'sidebar_right'  && !isset($_COOKIE['themeple_sidebar'])) || (isset($_COOKIE['themeple_sidebar']) && $_COOKIE['themeple_sidebar'] == 'right' )) get_sidebar();
?>

            </div>
        </div>
</section>

<?php
    get_footer();


?>

Let me know if you need to see more code.

  • I think we could actually see less code. Can you remove all the extra things in these code samples that don't directly affect the outcome (like the html in the template output)? – guiniveretoo Feb 12 '15 at 20:33
  • @guiniveretoo I shaved off what I could. I hope that helps. Thanks for the help in advance. – Lauren F Feb 12 '15 at 20:54
  • your theme is doing some strange things. it looks like your blog template is a custom template associated to a page, so the main query contains that page's data. the pagination function references this main query to generate pagination. it looks like somewhere not visible in this code that main query is getting overwritten to contain the blog posts, and where ever that's happening, it's ignoring the current page number when it makes the query, giving you the same posts on every page. – Milo Feb 12 '15 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.