查看最新创建的类别 时间:2015-07-27 作者:Rafael 我正在我的网站上创建一个部分,显示最近创建的五个类别。我怎么能那样做?更新:下面的代码是我想要的,只是想知道如何按顺序应用,如果是最新发布的类别。<?php $cat = get_query_var(\'cat\'); $categories=get_categories(\'child_of=\'.$cat); if ($categories) { ?> <div class="subcat-archive"> <?php $cat = get_query_var(\'cat\'); $categories=get_categories(\'child_of=\'.$cat); if ($categories) { foreach($categories as $term) { echo $title . \'<a href="\' . get_category_link( $term->term_id ) . \'" title="\' . sprintf( __( "View all posts in %s" ), $term->name ) . \'" \' . \'>\' . $term->name.\'</a> | \'; } } ?> </div> <?php } else { ?> <?php } ?> 2 个回复 SO网友:mmm 类别的id为自动递增,因此可以按id排序以找到最后一个类别:$args = array( "type" => "post", "orderby" => "id", "order" => "DESC", "number" => "5", "taxonomy" => "category", "hide_empty" => FALSE, // TRUE or FALSE depending what you want ); $categories = get_categories($args); SO网友:prempal sharma 将此代码用于访问类别$args = new WP_Query( array( \'type\' = \'post\', \'taxonomy\' = \'taxonomy_name\', \'order\' = \'ASC\', \'orderby\' = \'id\' )); //this function are used for access all categories $query = get_categories($args); 结束 文章导航