我需要按照一个非常具体的顺序列出帖子,这个顺序与帖子的日期、标题或WordPress能帮我弄清楚的任何东西都无关。当我在一个类别和类别存档页面上列出帖子时,我需要使用这个顺序。
有没有可能这样做,如果$idlist是一个按我想要的顺序排列的post-id数组,它可以循环遍历每个post-id?
<?php query_posts(post_id=$idlist); ?>
<?php the_permalink(); ?> etc...
我需要按照一个非常具体的顺序列出帖子,这个顺序与帖子的日期、标题或WordPress能帮我弄清楚的任何东西都无关。当我在一个类别和类别存档页面上列出帖子时,我需要使用这个顺序。
有没有可能这样做,如果$idlist是一个按我想要的顺序排列的post-id数组,它可以循环遍历每个post-id?
<?php query_posts(post_id=$idlist); ?>
<?php the_permalink(); ?> etc...
首先,query_posts
is terrible 不使用它。它可以做各种有趣的事情,比如搞乱非常有用的条件标记,比如is_singular
诸如此类,以及分页混乱。
没有钩住posts_orderby
通过SQL筛选和编写一些自定义订单,最好使用post__in
argument 结合post__in
orderby WP 3.5中添加的参数。
示例:
<?php
$custom_query = new WP_Query(array(
\'post__in\' => array(1, 2, 4, 5, /* whatever your post ID\'s are here */),
\'orderby\' => \'post__in\',
));
while ($custom_query->have_posts()) {
$custom_query->the_post();
// use the normal template tags here
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php
}
// restore the original query
wp_reset_query();
我试图在一个名为“提问”的子页面上过滤查询,以列出用户最近提交的所有问题,但在进入该页面时,我得到了404。刷新permalink结构并没有解决该问题。当前设置为月和名称。创建一个新问题可以正常工作,我可以访问新帖子。自定义分类法也可以正常工作,但归档页面不能正常工作。这是我正在使用的代码。Post typefunction question_post_type() { $labels = array( \'name\' => _