問題描述
我嘗試過這樣做:
<?php $count = count($custom_posts); ?>
<h2><?php echo $count; ?></h2>
在迴圈結束時:
<?php if ( bbp_get_forum_title() == 'Test Forum 1' ) : ?>
<?php $custom_posts = new WP_Query(); ?>
<?php $custom_posts->query('post_type=blocks&location=Business and Finance&order=DESC'); ?>
<?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
<div class="ad">
<?php the_content(); ?>
</div>
<?php $count = count($custom_posts); ?>
<h2><?php echo $count; ?></h2>
<?php endwhile; ?>
<?php endif; ?>
但是,不是總共的帖子,我得到這個輸出:
Translation 1
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim 1
有什麼建議來解決這個問題?
最佳解決方案
得到總數的正確方法是:
<?php $count = $custom_posts->post_count; ?>
http://codex.wordpress.org/Class_Reference/WP_Query#Properties
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。