[resolved] Page of Posts and PageNavi (5 posts)

  1. Pioneer Valley Web Design
    Posted 1 year ago #

    I am attempting to rewrite the referenced Page of Posts for Twenty Eleven Child theme to include PageNavi pagination...nothing I have read, researched or tried is fully working...


    I guess there are two parts, the first being how to properly output ALL posts (not just one category) and second, include PageNavi navigation once I can get pagination functioning....


    It works great everywhere else I had used in, except in this page of posts...

    Last, why is this page of posts written so differently than category.php...or other included twentyeleven template files...not closing php at each section etc...

    I've done plenty of customizing with php and child themes, but this has me stumped!


  2. referring to the code of 'Page-of-Posts':

    how to properly output ALL posts

    for example, change the query parameters to:

    $args = array(
    	// use any of the parameters from http://codex.wordpress.org/Class_Reference/WP_Query#Parameters to suit your use.
    	'post_type' => 'post',
    	'paged' => $paged

    include PageNavi navigation once I can get pagination functioning...

    for example, integrate wp-pagenavi ( http://scribu.net/wordpress/wp-pagenavi/wpn-2-74.html ) instead of this line (analogous for 'nav-above'):
    twentyeleven_content_nav( 'nav-below' );


    <nav id="#nav-below">
    			<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
    <?php if( function_exists('wp_pagenavi') ) : wp_pagenavi( array( 'query' => $list_of_posts ) );
    else : ?>
    			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ), $list_of_posts->max_num_pages ); ?></div>
    			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ), $list_of_posts->max_num_pages ); ?></div>
    <?php endif; ?>
    		</nav><!-- #nav-below -->

    example of the full template:

    why is this page of posts written so differently than category.php

    seems to be just an example, written by someone in its own style; you can obviously base your 'page-of-posts' template on the code of category.php ...

  3. Pioneer Valley Web Design
    Posted 1 year ago #

    First, thank you very much for you clear answers and functioning code example...It is working here.

    I do have one more question:

    When Page 2 is selected, while the second page of posts does now show, the page refreshes and goes to the top of the page...Have you had to deal with this before? Would be a better user experience if taken to top of page 2 posts...

  4. a:
    you could suppress the showing of the 'page' content and comment form on 'page 2' etc by changing this line near the top of the code:

    if( ! is_paged() ) get_template_part( 'content', get_post_format() );

    and you could add anchor tags to the 'wp-pagenavi' links;
    for example with this filter function:

    add_filter('get_pagenum_link', 'get_pagenum_link_anchor_tag');
    function get_pagenum_link_anchor_tag( $link ) {
    $link .= '#content';
    return $link;
  5. Pioneer Valley Web Design
    Posted 1 year ago #

    Great! I used 'a':

    I replaced (from your most graciously added link)

    get_template_part( 'content', get_post_format() );


    if( ! is_paged() ) get_template_part( 'content', get_post_format() );

    And it works wonderfully now!
    Thanks and topic resolved!

Topic Closed

This topic has been closed to new replies.

About this Topic