我按照自定義字段值的降序排列帖子,我想知道是否有方法按降序查找第n個帖子。WordPress的 - 如何獲得循環的第n個職位?
例,順序是:
1st from top: id = 9
2nd from top: id = 5
3rd from top: id = 6
現在,我使用get_template_part()
顯示帖子。
我想知道是否有什麼東西get_template_part_of_post(3rd-from-top)
。
<div class="onethird">
<?php
$count_posts = wp_count_posts("ott_products", "");
$published_posts_orig = $count_posts->publish;
$published_posts = $published_posts_orig + (3 - ($published_posts_orig % 3));
$i = 0;
if (have_posts()) : while($query->have_posts()) :
echo $i . " " . $published_posts;
$i = $i + 3;
$query->the_post();
get_template_part('content', 'category');
if ($i % 3 === 2) :
if (($i - 2 == $published_posts)) :
$i = 3;
endif; endif;
if ($i % 3 === 1) :
if (($i - 1 == $published_posts)) :
echo "</div><div class='onethird last'>";
$i = 2;
endif; endif;
if ($i % 3 === 0) :
if (($i == $published_posts)) :
echo "</div><div class='onethird'>";
$i = 1;
endif; endif;
endwhile;
else :
get_template_part('no-results', 'archive');
endif;
?>
</div>
這就是我目前使用的。這將帖子分成三列。
變量i
將從上到下的三列變爲從左到右。
以前,我有顯示類似的帖子:
(Total 9 posts)
1 4 7
2 5 8
3 6 9
有了它,我得到的i
到:現在
(Total n posts)
1 2 3
4 5 6
...
,問題是,我不能讓i
日發佈顯示。帖子仍然進來第一順序。
感謝您的答案,我編輯了上面的代碼,以解釋爲什麼這不起作用。 – NamanyayG 2013-02-08 16:05:13