好吧,我已经盯着这个看了近一个小时了,但无法让它发挥作用。我正在使用 WordPress,系统中有 12 个帖子。在管理中,我将其设置为每页显示 5 个帖子。在我的主题中,我尝试在底部显示分页(上一页、1、2、3、4、下一页)。我在 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 循环都工作得很好。分页只是没有打印出来。
看来Wordpresspaginate_links
函数需要一个参数。
我会尝试他们的默认示例,看看它是否有效。
<?php
paginate_links(array(
'base' => '%_%',
'format' => '?page=%#%',
'total' => 1,
'current' => 0,
'show_all' => False,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => False,
'add_fragment' => ));
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)