未显示分页/上一页和下一页链接

时间:2013-06-01 作者:user1255049

我的分页链接无法正常工作,甚至无法显示。我已经尝试了代码的几种变体,但这里是我在家里的。php:

<?php get_header(); ?> 
<?php get_sidebar(); ?> 

<div id="blog">
    <?php if (have_posts()) : ?>  
        <?php while (have_posts()) : the_post(); ?>  
        <div class="post" id="post-<!--?php the_ID(); ?-->">
    <div class="post_meta">
        <h2><a href="<!--?php the_permalink() ?-->" rel="bookmark" title="Permanent Link to 
            <?php the_title(); ?>"><?php the_title(); ?></a></h2>
        <p class="post_date"><?php the_time(\'F jS, Y\') ?></p>
    </div><!-- end blog_meta -->
    <div class="post">
        <?php the_content(\'Read the rest of this entry »\'); ?>
        <img src="<?php bloginfo(\'template_directory\'); ?>/img/dots_small.png" class="divider" alt="post divider">
    </div><!-- end post -->
    <div class="pagination">
        <?php
            previous_post_link(\'<span class="left">&laquo; %link</span>\');
            next_post_link(\'<span class="right">%link &raquo;</span>\');
        ?>                          
    </div><!-- end pagination -->
    <?php endwhile; ?>

     <?php else : ?>  
        <h2 class="center">Not Found</h2>  
        <p class="center">Sorry, but you are looking for something that isn\'t here.</p>  
        <?php include (TEMPLATEPATH . "/searchform.php"); ?>  
    <?php endif; ?>
</div><!-- end blog -->

 <?php get_footer(); ?> 

1 个回复
最合适的回答,由SO网友:gwdo 整理而成

好的,这里似乎有两个错误:

您应该使用posts_nav_link() 而不是previous_post_link()next_post_link(). 您使用的函数指向上一篇/下一篇文章,而不是页面。您可以参考WordPress Codex 了解更多信息。

你应该posts_nav_link() after endwhile 这样就不会对页面上显示的每一篇文章摘录重复。

因此代码应该如下所示:

<?php get_header(); ?> 
<?php get_sidebar(); ?> 

<div id="blog">
    <?php if (have_posts()) : ?>  
        <?php while (have_posts()) : the_post(); ?>  
        <div class="post" id="post-<!--?php the_ID(); ?-->">
    <div class="post_meta">
        <h2><a href="<!--?php the_permalink() ?-->" rel="bookmark" title="Permanent Link to 
            <?php the_title(); ?>"><?php the_title(); ?></a></h2>
        <p class="post_date"><?php the_time(\'F jS, Y\') ?></p>
    </div><!-- end blog_meta -->
    <div class="post">
        <?php the_content(\'Read the rest of this entry »\'); ?>
        <img src="<?php bloginfo(\'template_directory\'); ?>/img/dots_small.png" class="divider" alt="post divider">
    </div><!-- end post -->
    <?php endwhile; ?>
    <div class="pagination">
        <?php posts_nav_link(); ?>               
    </div><!-- end pagination -->
     <?php else : ?>  
        <h2 class="center">Not Found</h2>  
        <p class="center">Sorry, but you are looking for something that isn\'t here.</p>  
        <?php include (TEMPLATEPATH . "/searchform.php"); ?>  
    <?php endif; ?>
</div><!-- end blog -->

 <?php get_footer(); ?> 
希望这对我有用。

结束

相关推荐

Pagination stops at page 6

下面的循环工作得很好,除了分页总是在第6页停止之外。无论我指定什么参数,它都不会显示超过6页的内容。有人知道为什么吗?<?php $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1; $idxargs = array( \'posts_per_page\' => \'1\', \'paged\' =>