我正在使用@ Ellum2009(http://stackoverflow.com/q/4160319/705100)的此解决方案,按分类术语输出自定义帖子类型。该示例来自链接:
<?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(); ?>
但是,此解决方案不允许进一步对条目进行排序。它只是先输入最后一个条目。我想我可以为每个术语创建子分类,并将它们标记为“第一个”,“第二个”,“第三个”等。然后,用户可以检查管理界面中的相应框以控制排序顺序
我的问题是,我如何输出已排序的内容?
谢谢!
答案 0 :(得分:1)
我对分类法知之甚少,但WP_Query确实支持orderby和order参数 - 这些在你的情况下不起作用吗?
<?php $posts = new WP_Query(array(
'taxonomy' => 'type-mario',
'term' => 'games',
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'ASC'
)); ?>
<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(); ?>