WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Page of Posts and PageNavi

[Resolved] Page of Posts and PageNavi

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Michael

    @alchymyth

    Forum Moderator

    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' );

    example:

    <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:
    http://pastebin.com/M8dcazSa

    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 …

    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…

    Moderator Michael

    @alchymyth

    Forum Moderator

    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() );

    b:
    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;
    }

    Great! I used ‘a’:

    I replaced (from your most graciously added link)

    get_template_part( 'content', get_post_format() );

    with:

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

    And it works wonderfully now!
    Thanks and topic resolved!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Page of Posts and PageNavi’ is closed to new replies.