tep*_*.no 14 wordpress loops count
有没有办法在Wordpress循环代码中获取许多项目:
<?php while (have_posts()) : the_post(); ?>
Run Code Online (Sandbox Code Playgroud)
此循环列出了帖子.我需要将某些类添加到前3个,具体取决于它们的总数.
Sun*_*tva 24
您可以使用post_count属性的$WP_Query,就像这样:
$wp_query->post_count
Run Code Online (Sandbox Code Playgroud)
请注意与之相关的差异found_posts,这些差异虽然与查询匹配,但未显示(例如,用于分页).您可能希望根据您的具体情况使用其中一个.
Boj*_*jić 14
这是一种方法:
<?php
$count = 0; //set up counter variable
while (have_posts()) : the_post();
$count++; //increment the variable by 1 each time the loop executes
if ($count<4) {
// here put the special code for first three
}
// here put the code for normal posts
endwhile;
?>
Run Code Online (Sandbox Code Playgroud)