我有以下内容来显示我的类别列表:
$categories = get_categories( $args );
foreach ( $categories as $category ) {
echo \'<li><img src=""/><a href="\' . get_category_link( $category->term_id ) . \'" rel="bookmark">\' . $category->name . \'\' . \'\' . $category->description . \'</a></li>\';
}
但我正在使用“categories images”插件为每个类别分配一个图像(这是
img src=”/>
在代码内为。在src=“”中,我需要获得以下IF语句:
<?php if (function_exists(\'z_taxonomy_image_url\')) echo z_taxonomy_image_url(); ?>
甚至只是:
z_taxonomy_image_url();
我怎样才能做到这一点?
SO网友:SkyShab
以下是我的看法:
$categories = get_categories( $args );
foreach ( $categories as $category )
{
$image = (function_exists(\'z_taxonomy_image_url\') && z_taxonomy_image_url($category->term_id) ) ? sprintf(\'<img src="%s">\', z_taxonomy_image_url($category->term_id) ) : \'\';
echo sprintf(\'<li>%s<a href="%s" rel="bookmark">%s %s</a></li>\', $image, get_category_link( $category->term_id ), $category->name, $category->description);
}