【发布时间】:2021-07-15 20:15:52
【问题描述】:
我在 WordPress 的自定义主页中有一个自定义循环,它正在拉出 4 个帖子,中间有一些横幅。一切正常,但是分页总是显示相同的帖子。有没有办法给这个自定义循环添加分页?
我的 index.php 代码:
<?php
query_posts(array(
'post_type' => 'post',
'showposts' => 4,
) );
?>
<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 3) : ?>
<!-- banners -->
<a href="<?php the_permalink(); ?>"> <h1> <?php the_title(); ?> </h1> </a>
<?php the_content(); ?>
<?php else : ?>
<a href="<?php the_permalink(); ?>"> <h1> <?php the_title(); ?> </h1> </a>
<?php the_content(); ?>
<!-- banners -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<p align="center"><?php posts_nav_link(); ?></p>
【问题讨论】:
-
您需要修改查询以使用分页,请访问documentations here
-
这是我在打开帖子之前的第一次尝试,遗憾的是没有成功。
-
这就是您在 index.php 中的所有代码吗?
-
@beluoso Joint 的答案正是来自the documentation 我推荐给你的,你确定你以前试过吗?
-
当然可以,我可以看到它在那里有些相似,一些细微的差异使它起作用:现在使用 'paged' => 和 docs $paged =。抱歉,我的技能有限,我还没有尝试过这种改变。
标签: wordpress pagination