1

我想将其实现<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />到以下功能中。

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 中的类别列表,我有另一个插件,它允许您为每个类别设置图像,所以我试图显示它......

4

1 回答 1

2
if($cat->category_parent == 0) 
{
    $html .= '<img src="' . 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 .= '<img src="' . z_taxonomy_image_url($ccat->term_id) . '" />';*/
            $html .= '<p>' . $ccat->cat_name . '</p>';
            $html .= '<p>' . $ccat->category_description . '</p>';
        }
    }
}
于 2012-09-23T13:56:34.413 回答