Show the category title, description and a url to it\'s archive by using it\'s category ID:
<获取类别标题:
get_the_category_by_ID()获取类别描述(ID可选):
category_description()获取类别存档URL:
get_category_link()Get the Ids of the oldest and newest post in that category:
// Get oldest post ID
$posts = get_posts( array(
\'category\' => 1,
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
) );
$oldest_post_id = $posts[0]->ID;
// Get newest post ID
$posts = get_posts( array(
\'category\' => 1,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
) );
$newest_post_id = $posts[0]->ID;
Sort an array of category ids by the date of the latest post:
function get_categories_by_the_date() {
$categories_by_the_date = array();
$categories = get_categories();
foreach ( $categories as $category ) {
$posts = get_posts( array(
\'category\' => $category->term_id,
\'orderby\' => \'date\',
\'order\' => \'DESC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
) );
$categories_by_the_date[strtotime($posts[0]->post_date)] = $category->term_id;
}
krsort($categories_by_the_date);
return array_values($categories_by_the_date);
}