好吧,我已经盯着这个看了将近一个小时了,但无法让它工作。我正在使用 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 循环获取列表中的第一个帖子并将其显示在自己的特殊 block 中。第二个 while 循环获取剩余的 4 个帖子。这两个 while 循环都工作得很好。分页只是没有打印出来。
最佳答案
看起来 Wordpress paginate_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' => ));
?>
关于php - 在 WordPress 主题中对帖子进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5864578/