我为我的模板建立了2个自定义职位(消防员和马里奥),我为他们每个人建立了2个分类法(type-mario and the长期游戏,类型消防员和术语游戏) 目前我使用query_posts()显示与他们的术语链接的帖子的标题,但我想用get_posts()代替。get_posts()而不是query_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(); ?>
<?php query_posts(array('type-firemen' => 'games', 'showposts' => 10)); ?>
<p> Firemen 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(); ?>
它工作得很好,但我敢肯定,这是更好地使用get_posts()来显示这些标题2个职位,但我不知道该怎么做。
PS:请记住,有2级海关的职位,而不是经典的帖子,我的事业必须建立一个分类为每个我的职位与同期限的......
感谢您的建议。
这里是一个解决方案:
<?php $posts = new 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(); ?>