想做个类似于CMS式的主题,那么需要按照文章分类来显示文章,但是牵扯到一个问题,获取分类的文章必须获得分类目录的ID,ID一般获取很繁琐,所以我们用更好的办法,直接输出所有分类目录及分类目录的ID,这样可以放在主题的配置页面中,以便方便参考。
<code>
//获取所有站点分类id
function Bing_show_category() {
global $wpdb;
$request = "SELECT $wpdb->terms.term_id, name FROM $wpdb->terms ";
$request .= " LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id ";
$request .= " WHERE $wpdb->term_taxonomy.taxonomy = 'category' ";
$request .= " ORDER BY term_id asc";
$categorys = $wpdb->get_results($request);
foreach ($categorys as $category) { //调用菜单
$output = '<span>'.$category->name."(<em>".$category->term_id.'</em>)</span>';
echo $output;
}
}</code>
//获取所有站点分类id
function Bing_show_category() {
global $wpdb;
$request = "SELECT $wpdb->terms.term_id, name FROM $wpdb->terms ";
$request .= " LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id ";
$request .= " WHERE $wpdb->term_taxonomy.taxonomy = 'category' ";
$request .= " ORDER BY term_id asc";
$categorys = $wpdb->get_results($request);
foreach ($categorys as $category) { //调用菜单
$output = '<span>'.$category->name."(<em>".$category->term_id.'</em>)</span>';
echo $output;
}
}</code>