本文介绍了wp-pagenavi无法正常工作...它会更改实际网址,但不会更改帖子本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,我已经在自己的页面模板上创建了一个单独的新博客页面,名为blog.php,我在每个页面中拉了5条帖子,第一页效果很好,并链接到他们的单个帖子也被附上.当我尝试将wp-pagenavi添加到我的nav-below中时,我遇到了问题.发生的是,我将单击以转到下一页,它更改了URL,但是帖子应与以前保持不变,此时应将其切换到下一组.我不知道您是否可以在index.php之外使用wp-pagenavi,但是如果有人可以让我知道我在这里做错了什么,为什么我继续收到同样棒的帖子,并且会感到非常赞赏.我在blog.php上拥有一个博客,而这就是我试图开始工作的文件.我已经在下面发布了.请让我知道我能做什么谢谢你!

The issue I am having is I have created a separate new blog page on its own page template being called blog.php, I have pulled 5 posts into each page and the first page work great and link to the single posts that they are attached too. When I try to add wp-pagenavi into my nav-below I run into issues. What is happening is I will click to go the next page and it changes the url, but the posts remain the same as before, when it should be switching them to the next set. I don't know if you can use wp-pagenavi outside of index.php but if anyone can let me know what I am doing wrong here and why I continue to get the same posts that would be awesome and greatly appeciated. I have one of my blogs on blog.php and that is the file I am trying to get to work. I have posted that below. Please let me know what I can do 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 is activated ?>

<?php wp_pagenavi(); // Use PageNavi ?>

        </div><!-- end #nav-below --> 
    </div><!-- end content -->

<?php get_footer(); ?>  

推荐答案

尝试一下:

<?php $paged = 1;
 if ( get_query_var('paged') ) $paged = get_query_var('paged');
 if ( get_query_var('page') ) $paged = get_query_var('page');
 $temp = $wp_query; 
 $wp_query = null; 
 $wp_query = new WP_Query(); 
 $wp_query->query('posts_per_page=5'.'&paged='.$paged);?>
 <?php if ( $wp_query->have_posts() ) : ?>
     //your loop code goes here
   <?php wp_pagenavi(); ?>
  <?php endif; // end have_posts() check ?>
 <?php 
  $wp_query = null; 
  $wp_query = $temp;  // Reset
 ?>

这篇关于wp-pagenavi无法正常工作...它会更改实际网址,但不会更改帖子本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 07:25