WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Thirteen
[resolved] Twenty Thirteen pagination not working on Page of Posts (11 posts)

  1. jamminjames
    Member
    Posted 2 months ago #

    I have a Twenty Thirteen child theme and have a page of posts by category set up for the home page. I'm using the suggested Page of Posts (pageofposts.php) found at http://codex.wordpress.org/Page_Templates.

    It has the code '<?php twentythirteen_paging_nav(); ?>' in it, but the pagination is not working the way it does with a regular home page (when you have a 'latest posts' home page, rather than static), even though the index.php page has the same coding.

    Any idea why, and how I can fix it? Thanks for any help.

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 months ago #

    twentythirteen_paging_nav() only works for the default query $wp_query, not for custom queries like $list_of_posts -

    (i.e. the Codex example is not fully accurate)

    you could add some modified code (taken from twentythirteen_paging_nav()) directly into the page template instead of the line <?php twentythirteen_paging_nav(); ?>

    <?php	// Don't print empty markup if there's only one page.
    	if ( $list_of_posts->max_num_pages >= 2 ) : ?>
    	<nav class="navigation paging-navigation" role="navigation">
    		<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
    		<div class="nav-links">
    
    			<?php if ( get_next_posts_link( '', $list_of_posts->max_num_pages ) ) : ?>
    			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ), $list_of_posts->max_num_pages ); ?></div>
    			<?php endif; ?>
    
    			<?php if ( get_previous_posts_link( '', $list_of_posts->max_num_pages ) ) : ?>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), $list_of_posts->max_num_pages ); ?></div>
    			<?php endif; ?>
    
    		</div><!-- .nav-links -->
    	</nav><!-- .navigation -->
    	<?php endif; ?>
  3. jamminjames
    Member
    Posted 2 months ago #

    alchymyth,

    Thanks for the idea. However, while it now shows the 'Older Posts' link, when you hit it, it just brings up the same posts again, while saying '/page/2/' in the url.

    I tried adding the next section as well, so the whole piece of code I inserted is now:

    <?php	// Don't print empty markup if there's only one page.
    	if ( $list_of_posts->max_num_pages >= 2 ) : ?>
    	<nav class="navigation paging-navigation" role="navigation">
    		<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
    		<div class="nav-links">
    
    			<?php if ( get_next_posts_link( '', $list_of_posts->max_num_pages ) ) : ?>
    			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ), $list_of_posts->max_num_pages ); ?></div>
    			<?php endif; ?>
    
    			<?php if ( get_previous_posts_link( '', $list_of_posts->max_num_pages ) ) : ?>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), $list_of_posts->max_num_pages ); ?></div>
    			<?php endif; ?>
    
    		</div><!-- .nav-links -->
    	</nav><!-- .navigation -->
    	<?php	// Don't print empty markup if there's nowhere to navigate.
    	$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
    	$next     = get_adjacent_post( false, '', false );
    
    	if ( ! $next && ! $previous )
    		return;
    	?>
    	<nav class="navigation post-navigation" role="navigation">
    		<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1>
    		<div class="nav-links">
    
    			<?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
    			<?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
    
    		</div><!-- .nav-links -->
    	</nav><!-- .navigation -->
    
    }
    	<?php endif; ?>

    However, while that now brings up a link to the previous post and next post below the 'Older Posts', clicking on 'Older Posts' still brings up the first posts, not the previous ones.

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 months ago #

    I actually tested the suggested code in a copy of the template as it was posted in the Codex, in a local installation in a child theme of Twenty Thirteen, and experienced no problems with the pagination.

    can you post the full code of your page-of-posts template?

  5. jamminjames
    Member
    Posted 2 months ago #

    Sure, here it is (I took that part I said I had added back out):

    <?php
    /*
    Template Name: Page Of Posts
    */
    
    /* Choose categories to use at line 35 'category_name' */
    
    get_header(); ?>
    
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    		<div id="home-slider" class="widget-top">
    			<?php dynamic_sidebar( 'widget-top1' ); ?>
    		</div>
            <?php
            /* The loop: the_post retrieves the content
             * of the new Page you created to list the posts,
             * e.g., an intro describing the posts shown listed on this Page..
             */
            if ( have_posts() ) :
                while ( have_posts() ) : the_post();
    
                  // Display content of page
                  get_template_part( 'content', get_post_format() );
                  wp_reset_postdata();
    
                endwhile;
            endif;
    
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
            $args = array(
                /* Change these category SLUGS to suit your use.
    			   Separate categories by comma, all within one set of quotes */
                'category_name' => 'California Stage presents',
                'paged' => $paged
            );
    
            $list_of_posts = new WP_Query( $args );
            ?>
            <?php if ( $list_of_posts->have_posts() ) : ?>
    			<?php /* The loop */ ?>
    			<?php while ( $list_of_posts->have_posts() ) : $list_of_posts->the_post(); ?>
    				<?php // Display content of posts ?>
    				<?php get_template_part( 'content', get_post_format() ); ?>
    			<?php endwhile; ?>
    
    	<?php	// Don't print empty markup if there's only one page.
    	if ( $list_of_posts->max_num_pages >= 2 ) : ?>
    	<nav class="navigation paging-navigation" role="navigation">
    		<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
    		<div class="nav-links">
    
    			<?php if ( get_next_posts_link( '', $list_of_posts->max_num_pages ) ) : ?>
    			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ), $list_of_posts->max_num_pages ); ?></div>
    			<?php endif; ?>
    
    			<?php if ( get_previous_posts_link( '', $list_of_posts->max_num_pages ) ) : ?>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ), $list_of_posts->max_num_pages ); ?></div>
    			<?php endif; ?>
    
    		</div><!-- .nav-links -->
    	</nav><!-- .navigation -->
    	<?php endif; ?>
    
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>
    
    		</div><!-- #content -->
    		<div id="content-bgr" class="site-content-bgr"></div>
    	</div><!-- #primary -->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  6. alchymyth
    The Sweeper & Moderator
    Posted 2 months ago #

    the only thing I see is the use of the category title instead of the slug in this line:

    'category_name' => 'California Stage presents',

    try and correct that to use the SLUG:

    'category_name' => 'california-stage-presents',

    double check that this is the correct slug of your category - under dashboard - posts - categories

    do the shown posts belong to the right category?

  7. jamminjames
    Member
    Posted 2 months ago #

    Same results either way. Yes, it is bringing up the proper category, and there are five posts in that category, with the first page showing three, so the older posts should get the last two, but it doesn't. Weird.

    Here's the site.

  8. jamminjames
    Member
    Posted 2 months ago #

    Also, I have another post in support here asking about changing the home page stories to excerpts. You seem to be knowledgeable about TwentyThirteen, can you help me with that?

    I'd like the first post to be full, but subsequent ones shown as excerpts. I have the 'more' divider set up on the posts, but it's not showing as excerpts. The odd thing is, when I had the home page as recent blog posts instead of a static page, it did that. Now it doesn't.

    The reason I changed to a static page, which started all these problems, is when I changed to restricting the home page to a category, it stopped showing the slider on top. (I used <?php query_posts('cat=1&showposts='.get_option('posts_per_page')); ?> before the loop to restrict it to one category.)

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 months ago #

    what slider is running on the home page?
    does the problem with 'page 2' continue if you temporarily remove the slider?

    The reason I changed to a static page, which started all these problems, is when I changed to restricting the home page to a category, it stopped showing the slider on top. (I used <?php query_posts('cat=1&showposts='.get_option('posts_per_page')); ?> before the loop to restrict it to one category.)

    the general recommended way to do this is via 'pre_get_posts' action;
    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

    specific:
    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Show_Only_One_Category_on_Home_Page

    (not tested how this works with the slider)

  10. jamminjames
    Member
    Posted 2 months ago #

    I'm using the WP Slider. I tried removing it, makes no difference.

    I'll see what I can do with the links you provided. Thanks!

  11. jamminjames
    Member
    Posted 2 months ago #

    EXCELLENT! THANK YOU!!! That solved all my problems. I appreciate your help very much!

Reply

You must log in to post.

About this Theme

About this Topic