wordpress - wp-pagenavi not working... It changes the actual url but not the posts themselves? -
the issue having have created separate new blog page on own page template being called blog.php, have pulled 5 posts each page , first page work great , link single posts attached too. when try add wp-pagenavi nav-below run issues. happening click go next page , changes url, posts remain same before, when should switching them next set. don't know if can use wp-pagenavi outside of index.php if can let me know doing wrong here , why continue same posts awesome , appeciated. have 1 of blogs on blog.php , file trying work. have posted below. please let me know can thank you!
<?php /** * template name: blog page */ get_header(); ?> <div id="content"> <?php query_posts("posts_per_page=5"); ?> <?php //the loop. if( have_posts() ): while( have_posts() ): the_post(); ?> <article id="post-1" <?php post_class( 'clearfix' ); ?>> <h2 class="entry-title"> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2> <div class="postmeta"> <span class="author"> posted by: <?php the_author(); ?> </span> <span class="date"> <?php the_date(); ?> </span> <span class="num-comments"> <?php comments_number('no comments yet', 'one comment', '% comments'); ?></span> <span class="categories"> <?php the_category(); ?> </span> <span class="tags"> <?php the_tags(); ?> </span> </div><!-- end postmeta --> <?php if( has_post_thumbnail() ): ?> <div class="thumb"> <?php the_post_thumbnail( 'thumbnail' ); ?> </div> <?php endif; ?> <div class="entry-content"> <?php if( is_single()): the_content(); else: the_excerpt(); endif; ?> </div> <?php comments_template(); ?> </article><!-- end post --> <?php endwhile; else: ?> <h2>sorry, no posts found</h2> <?php endif; //end of loop. ?> <div id="nav-below" class="pagination"> <?php if(function_exists('wp_pagenavi')) // if pagenavi activated ?> <?php wp_pagenavi(); // use pagenavi ?> </div><!-- end #nav-below --> </div><!-- end content --> <?php get_footer(); ?>
here's think should do:
step 1: create page called 'blog' (presumably, did already)
step 2: throw away blog.php
template created
step 3: go admin -> settings -> reading, select "a static page" "front page displays", , select page "blog" "posts page" dropdown.
step 4: make copy of index.php
file, , rename home.php
. template applied new "home" page. replace default pagination in home.php
wp-pagenavi code.
step 5: modify query on brand new blog page putting in functions.php
file:
add_action( 'pre_get_posts','so16345510_pre_get_posts' ); function so16345510_pre_get_posts( $query ) { if( is_home() && $query->is_main_query() ){ $query->set( 'posts_per_page', 5 ); } return $query; }
Comments
Post a Comment