【发布时间】:2014-04-12 05:43:41
【问题描述】:
我正在处理一个修改过的 wordpress 循环,其中有一个 if 和 else 条件。代码在下面。
我想要做的是添加一个容器来容纳每个满足条件的帖子。这将对每个条件进行分组。
<div class="container">
<?php if (have_posts()) : ?>
<?php
$i = 1;
while (have_posts()) {
the_post();
// Add a DIV CONTAINER that holds the FIRST CONDITION
if ($i <= 3) {
the_title();
the_content();
// Add a DIV CONTAINER that holds the FIRST CONDITION
// Add a DIV CONTAINER that holds the SECOND CONDITION
} elseif ($i <= 9) {
the_title();
the_permalink();
// Add a DIV CONTAINER that holds the SECOND CONDITION
// Add a DIV CONTAINER that holds the THIRD CONDITION
} elseif ($i <= 13) {
the_title();
the_permalink();
// Add a DIV CONTAINER that holds the THIRD CONDITION
// Add a DIV CONTAINER that holds the FOURTH CONDITION
} elseif ($i <= 15) {
the_title();
// Add a DIV CONTAINER that holds the FOURTH CONDITION
// Add a DIV CONTAINER that holds the FIFTH CONDITION
} else {
the_title();
// Add a DIV CONTAINER that holds the FIFTH CONDITION
}
$i++;
}
?>
<?php else : ?>
<h2>No Posts Found</h2>
<?php endif; ?>
</div>
如果我在我的 cmets 所在的位置添加 echo '<div class="FirstCondition">';,就会发生这种情况。
它只会重复我添加的 div 容器。我需要的是添加一个简单的 DIV 容器来保存所有符合条件的帖子。
最终的输出是这样的:
<div class="FirstCondition">
Wordpress Published Post that meets the criteria for the First Condition
Wordpress Published Post that meets the criteria for the First Condition
Wordpress Published Post that meets the criteria for the First Condition
Wordpress Published Post that meets the criteria for the First Condition
</div>
<div class="SecondCondition">
Wordpress Published Post that meets the criteria for the Second Condition
Wordpress Published Post that meets the criteria for the Second Condition
Wordpress Published Post that meets the criteria for the Second Condition
Wordpress Published Post that meets the criteria for the Second Condition
</div>
<div class="ThirdCondition">
Wordpress Published Post that meets the criteria for the Third Condition
Wordpress Published Post that meets the criteria for the Third Condition
Wordpress Published Post that meets the criteria for the Third Condition
Wordpress Published Post that meets the criteria for the Third Condition
</div>
<div class="FourthCondition">
Wordpress Published Post that meets the criteria for the Fourth Condition
Wordpress Published Post that meets the criteria for the Fourth Condition
Wordpress Published Post that meets the criteria for the Fourth Condition
Wordpress Published Post that meets the criteria for the Fourth Condition
</div>
<div class="FifthCondition">
Wordpress Published Post that meets the criteria for the Fifth Condition
Wordpress Published Post that meets the criteria for the Fifth Condition
Wordpress Published Post that meets the criteria for the Fifth Condition
Wordpress Published Post that meets the criteria for the Fifth Condition
</div>
这可能吗?如何?请帮忙。
【问题讨论】:
标签: php html wordpress while-loop containers