php - PHP 循环和 For 循环
问题描述
我原以为这是直截了当的,但我对 The Loop 的理解是有限的。
我的 WordPress 网站上有大约 6 篇博文。但是,我只想在主页上显示其中的 2 个。
我认为嵌套在 For 循环中的循环会起作用,但无济于事。
下面是我的代码,这是行不通的。它循环 6 个帖子 3 次。所以它输出了 18 个帖子,而不是预期的 2 个。
<?php
for($x = 0; $x<=2; $x++) {
while(have_posts()) {
the_post(); ?>
<h2 class="blog-post-title"><?php the_title(); ?></h2>
<p class="blog-post-meta text-muted">
<?php the_time('F Y'); ?> by <a href="#"><?php the_author_posts_link(); ?> in <?php echo get_the_category_list(', '); ?></a>
</p>
<p><?php the_content(); ?></p>
<?php
}} ?>
解决方案
推荐阅读
- python - 对以下 python 列表的输出感到困惑
- ios - 如何解决“无法生成位码包,因为'AFNetworking framework/paytabs-iOS(UIColor+Helpers.o)'是在没有完整位码的情况下构建的”
- python - 将列表内容转换为可理解的命名元素
- c++ - C ++为什么将const char * / char []转换为std :: string时分配两次内存
- javascript - localstorage.getItem 只显示一个数据,尽管数组中有多个数据
- python - 每个类别的 ROC 曲线
- python - 使用 tensorflow 进行多类分类时遇到问题
- c - Kattis反转二进制数
- azure - Azure DataFactory 日志分析访问
- azure - Azure Cosmos 2020 年 6 月更新 - Gremlin API - “包含”不区分大小写?