实际上,我有一个PHP循环,在这个循环中,我给每个结果一个数字,从1开始,然后按照升序进行跟踪。产出如下:
1) C条
2) B条
3) A条
...but我想反转列表号,所以我得到了如下内容:
3) C条(条款的顺序不会改变,而是按日期递减)
2) B条
1) A条
下面是我的当前循环:
<?php
if (have_posts()) :
$counter = 1;
while (have_posts()) :
the_post(); ?>
<div>
<span class="count"><?php echo $counter; ?></span>
<?php the_title(); ?>
</div>
<?php
$counter++;
endwhile;
endif;
?>有什么简单的方法吗?非常感谢,
发布于 2012-11-19 16:46:20
The 对象有一个保存文章数量的变量。
$query->post_count这样,您的代码就可以变成:
<?php
if (have_posts()) :
global $wp_query;
$counter = $wp_query->post_count;
while (have_posts()) :
the_post(); ?>
<div>
<span class="count"><?php echo $counter; ?></span>
<?php the_title(); ?>
</div>
<?php
--$counter;
endwhile;
endif;
?>发布于 2012-11-19 16:40:34
如果有一个函数返回posts计数,例如count_posts() (只是猜测),就这样使用它:
<?php
if (have_posts()) :
$counter = wp_count_posts();
while (have_posts()) :
the_post(); ?>
<div>
<span class="count"><?php echo $counter; ?></span>
<?php the_title(); ?>
</div>
<?php
$counter--;
endwhile;
endif;
?>https://stackoverflow.com/questions/13458197
复制相似问题