【发布时间】:2011-08-17 09:35:56
【问题描述】:
好的,我已经盯着这个看了将近一个小时,但无法让它工作。我正在使用 WordPress,系统中有 12 个帖子。在管理员中,我将其设置为每页显示 5 个帖子。在我的主题中,我试图在底部显示分页 (prev,1,2,3,4,next)。我在 WordPress 指南上找到了 paginate_links() 函数,但它没有打印出任何内容......感谢任何帮助:
<?php get_header(); ?>
<div class="middle-container">
<div class="middle">
<div class="column main">
<div class="latest">
<?php
$i = 0;
if (have_posts()):
while (have_posts() && $i < 1):
the_post();
?>
<div class="image"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
</div>
<div class="content">
<h1><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<span class="date"><?php the_time('F jS, Y') ?></span>
<?php
the_excerpt();
?>
</div>
<?php
$i++;
endwhile;
endif;
?>
</div>
<ul class="posts">
<?php
$i = 0;
if (have_posts()):
while (have_posts() && $i < 4):
the_post();
?>
<li>
<h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<span class="date"><?php the_time('F jS, Y') ?></span>
<?php
the_excerpt();
?>
</li>
<?php
$i++;
endwhile;
endif;
?>
</ul>
<?php
echo paginate_links();
?>
</div>
<div class="column sidebar"></div>
</div>
</div>
<?php get_footer(); ?>
更多背景知识:代码中的第一个 while 循环抓取列表中的第一个帖子并将其显示在自己的特殊块中。第二个 while 循环抓取剩余的 4 个帖子。这两个 while 循环都可以正常工作。分页只是没有打印出来。
【问题讨论】:
-
这个问题应该迁移到wordpress.stackexchange.com
标签: php wordpress pagination