我正在用Wordpress写博客,帖子分页没有出现。帖子列表显示正确,但只有5个帖子(我有8个)和分页不工作。
<?php
if (have_posts()): while (have_posts()) : the_post(); ?>
<div class="all-post">
<?php
$args = array('category' => '');
$myposts = get_posts($args);
foreach ($myposts as $post) : setup_postdata($post); ?>
<div class="post">
<div class="post-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-details">
<div class="post-meta">
<span class="date"><?php the_time('j M, Y'); ?></span>
<!-- Categories -->
<span class="categories">
<?php
$category_ids = get_all_category_ids();
?><?php
$args = array('orderby' => 'slug', 'parent' => 0);
$categories = get_categories($args);
foreach ($categories as $category)
{
echo '<a href="' . get_category_link(
$category->term_id
) . '" rel="bookmark" class="category">' . $category->name . '' . $category->description . '</a>';
} ?>
</span>
</div>
<h2 class="post-title">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<a href="<?php the_permalink(); ?>" class="read-more">Read More</a>
</div>
</div>
<?php endforeach;
wp_reset_postdata(); ?>
</div>
<?php endwhile; ?>
<?php next_posts_link('Older posts'); ?>
<?php previous_posts_link('Newer posts'); ?>
<?php else: ?>
<?php endif; ?>
您可能没有设置任何posts_per_page
值,默认值为5。如果你想修改它为整个网站的博客/存档页面,修改posts_per_page值在阅读设置页面。
在$args
数组中,修改如下:
$args = array(
'posts_per_page'=> -1, // unlimited
'category' => ''
);
$posts = get_posts($args);
我对我的答案很谨慎(这就是为什么我给出2种方法来实现这一点),因为我不知道你给定的代码,如果主循环$args被修改。