我get_categories
用来在我的首页显示一个类别中的帖子,但我想按我定义的顺序排列类别,比如:
$cat_order = 5,2,4,1,3 //order by category ID
or
$cat_order = cat5,cat2,cat4,cat1,cat3 // order by cat name
下面是我当前的代码,它通过命令 catname, ASC
<?php
//for each category, show all posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => -1,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
foreach($posts as $post) {
setup_postdata($post); ?>
<article >
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
</article>
<?php
} // foreach($posts
} // if ($posts
} // foreach($categories
?>