Php 如何在WordPress中使HTML元素不在循环内循环
在WordPress中可以这样制作帖子列表吗Php 如何在WordPress中使HTML元素不在循环内循环,php,wordpress,Php,Wordpress,在WordPress中可以这样制作帖子列表吗 <div class="large-image"> <img src="http://example.com"> <h1>Title</h1> </div> <div class="post-row"><!-- this is not a loop --> <div class="
<div class="large-image">
<img src="http://example.com">
<h1>Title</h1>
</div>
<div class="post-row"><!-- this is not a loop -->
<div class="post-item"><!-- this is a loop -->
<img src="http://example.com">
<h1>Title</h1>
</div>
<div class="post-item"><!-- this is a loop -->
<img src="http://example.com">
<h1>Title</h1>
</div>
</div>
标题
标题
标题
我尝试了下面的代码,但是
总是包含在循环中
<?php
if ( have_posts() ) : $post_count = 0;
while ( have_posts() ) : the_post();
if ( $post_count = 0 ) { ?>
<div class="large-image">
<img src="http://example.com">
<h1>Title</h1>
</div>
<?php } ?>
<div class"post-row">
<?php if ( $post_count > 0 ) { ?>
<div class="post-item"><!-- this is a loop -->
<img src="http://example.com">
<h1>Title</h1>
</div>
<?php } ?>
</div><!-- /post-row -->
<?php
endwhile
endif;
?>
标题
标题
我想要的是
不要循环
我在stackoverflow中尝试了一些答案,但是post行总是循环
希望我能得到最好的答案。您必须将post row div移到while循环上方,您刚刚错过了放置位置,仅此而已
<?php if ( have_posts() ) : $post_count = 0;
if ( $post_count == 0 ) { ?>
<div class="large-image">
<img src="http://example.com">
<h1>Title</h1>
</div>
<?php } ?>
<div class"post-row">
<?php
while ( have_posts() ) : the_post();
if ( $post_count > 0 ) { ?>
<div class="post-item"><!-- this is a loop -->
<img src="http://example.com">
<h1>Title</h1>
</div>
<?php }
$post_count ++;
endwhile; ?>
</div><!-- /post-row -->
<?php endif; ?>
标题
标题
“但循环中始终包含了数据”-因为这是您放置数据的地方…所以请将其放在外部?你试过什么,问题出在哪里?顺便说一句,如果($post\u count=0)
-这是一个作业,不是比较。请仔细阅读。我想要的是
不要循环。如果尝试这个:(使用code)那么如果(have_posts()):$post_count=0有什么意义代码>应该是什么have_posts()
返回true意味着有帖子。也不正确,他们想要..
元素在
之前,但现在你已经将它放在了里面。好的,这是静态链接,你也可以将它向上移动让我编辑我的答案是的,我想要..
元素在
之前。我意识到我想要的WordPress开发实践有点复杂,但我希望通过在这里发布一个问题来找到答案。太好了!干得很好,伙计。谢谢你@Shakelahmad Welcome@ZapraGartiast