【问题标题】:WP-PageNavi Issues, Url changes but the posts remain the same?WP-PageNavi 问题,网址更改但帖子保持不变?
【发布时间】:2014-01-14 11:13:11
【问题描述】:

我遇到的问题是我在其自己的页面模板页面上创建了一个新的博客页面,称为 blog.php,我在每个页面中提取了 5 个帖子,第一页效果很好,并链接到他们的单个帖子也附上了。

当我尝试将 wp-pagenavi 添加到我的 nav-below 中时,我遇到了一个问题。发生的情况是我将单击转到下一页并更改 url,但帖子与以前保持一致,此时应该将它们切换到下一组。

我不知道您是否可以在 index.php 之外使用 wp-pagenavi,但是如果有人可以让我知道我在这里做错了什么以及为什么我会继续收到相同的帖子,那将非常棒并且非常感谢.我在 blog.php 上有我的一个博客,这就是我要开始工作的文件。我已经在下面发布了它的代码。

<?php
/**
 * Template Name: Blog Page  <?php query_posts("posts_per_page=8"); ?>
 */
 get_header(); ?>

    <div id="content">
    <?php query_posts( array( 'post_type' => 'post', '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()  OR is_page() ):

                    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') ): 
                 wp_pagenavi();
             else:
           ?>

            <?php next_posts_link( '&larr; Older Posts' ); ?>
            <?php previous_posts_link( 'Newer Posts &rarr;' ); ?>

            <?php endif; ?>
        </div><!-- end #nav-below --> 
    </div><!-- end content -->

<?php get_footer(); ?>  

【问题讨论】:

标签: wordpress plugins


【解决方案1】:

&lt;div id="content"&gt;之后有这个代码:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( array( 'post_type' => 'post', 'posts_per_page=5', 'paged' => $paged ) ); ?>

【讨论】:

  • 非常感谢你的摇滚!我一直在努力弄清楚这件事,非常感谢!!!!!!!
猜你喜欢
  • 2023-03-31
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-11
  • 2015-11-13
  • 2015-04-02
  • 2021-03-19
相关资源
最近更新 更多