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
噢,好吧,我明白了!非常感谢 –