問題描述
我目前使用 query_posts
顯示這些自定義的帖子,但我很確定我應該使用 get_posts()
正確寫入。
<?php query_posts( array( 'type-mario' => 'games', 'showposts' => 10 ) ); ?>
<p>Mario games</p>
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
謝謝你的建議。
最佳解決方案
Hi Elium2009:
使用你的程式碼,我想這是你正在尋找的? (請注意,WP_Query()
只是 get_posts()
的更直接版本):
<?php $posts = WP_Query(array(
'taxonomy' => 'type-mario'
'term' => 'games',
'posts_per_page' => 10
)); ?>
<p>Mario games</p>
<?php while ( $posts->have_posts() ) : $posts->the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
希望這可以幫助?
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。