1
我想將這個<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
實現爲以下函數。PHP:在php腳本中顯示圖像
function list_my_categories($exclude = '') {
if (!empty($exclude)) {
$exclude = 'exclude=' . $exclude;
}
$categories = get_categories($exclude);
$html = '';
foreach ($categories as $cat) {
if($cat->category_parent == 0) {
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
$html .= '<p>' . $cat->cat_name . '</p>';
$html .= '<p>' . $cat->category_description . '</p>';
$childcategories = get_categories('child_of='.$cat->cat_ID.'');
if(!empty($childcategories)){
foreach ($childcategories as $ccat) {
$html .= '<p>' . $ccat->cat_name . '</p>';
$html .= '<p>' . $ccat->category_description . '</p>';
}
}
}
}
return $html;
}
add_shortcode('show-cats', 'list_my_categories');
功能將顯示在WordPress的類別列表,我有另外一個插件,它允許您設置圖像的每個類別,所以我試圖證明它...
它工作!爲什麼灰色的位被註釋掉了?我應該擺脫它 –
如果需要圖像子類別,請取消註釋該代碼。 – doktorgradus
噢,好吧,我明白了!非常感謝 –