製作wordpress主題時,想要獲取所有分類相關信息,可以通過get_categories()函數,該函數可以返回與查詢參數相匹配的類別對象數組,該函數的變數與wp_list_categories()函數基本一致,且變數可被作為數組傳遞,也可在查詢句法中被傳遞。
函數用法:
$args參數及默認值:
『post』,
『child_of』 => 0,
『parent』 => 」,
『orderby』 => 『name』,
『order』 => 『ASC』,
『hide_empty』 => 1,
『hierarchical』 => 1,
『exclude』 => 」,
『include』 => 」,
『number』 => 」,
『taxonomy』 => 『category』,
『pad_counts』 => false );
?>
參數說明:
示例:顯示分類列表和分類描述以及包含的文章數目
『name』,
『order』 => 『ASC』
);
$categories=get_categories($args);
foreach($categories as $category) {
echo 『
- 『;
echo 『 name ) . 『」 『 . 『>』 . $category->name.』 『;
echo 『
『;
}
?>[/cc]
輸出html代碼:
參考文章:
修改WordPress文章默認排序的方法