<body >
其中數字為該分類的 ID 號,前提是主題模板必須使用函式:
<body <?php body_class(); ?>>
有了這個非常方便的功能,你就可以針對不同的分類定義不同的樣式風格。
將以下程式碼新增到您當前主題的 functions.php 檔案:
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes [] = 'cat-' . $category->cat_ID . '-id';
return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
應用例項:
比如:HotNewspro 主題,在分類 ID 為 6 的分類歸檔和文章頁面隱藏熱點文章 (頂部的四張圖片),可在主題樣式檔案 style 中新增:
.cat-6-id, #top_hot {
display: none;
}
舉一反三,可以定義其它任意位置的文字大小,背景顏色等與其它分類不同。