How to show image and description in Categories widget in wordpress

时间:2017-12-18 08:14:27

标签: wordpress

Hello friends i want so image and description in categories list widget for showing description i use below code:

in function.php

IOptions<AppSettings>

and in class-wp-widget-categories.php

function wpb_catlist_desc() {
    $string = '<ul>';
    $catlist = get_terms( 'category' );
    if ( ! empty( $catlist ) ) {
      foreach ( $catlist as $key => $item ) {
         $string .= '<li>'. $item->name . '<br />';
         $string .= '<em>'. $item->description . '</em> </li>';
      }
   }
$string .= '</ul>';

return $string; 
}
add_shortcode('wpb_categories', 'wpb_catlist_desc');

it is showing categories name and his description now i want to show categories image also. any one please help me how can i get that. i had try Categories Images plugin for show images but can't able to show

2 个答案:

答案 0 :(得分:0)

图片获取z_taxonomy_image_url($id)z_taxonomy_image($id)

if(z_taxonomy_image_url($item->term_id))
{
    $string .= '<img src ="'.z_taxonomy_image_url($item->term_id).'" style="width: 20%;">';
}

答案 1 :(得分:0)

您可以使用以下代码获取图像并将其附加到$ string。

 quote['SellTime'].head()


 Out[32]:
  0    94520
  1    94538
  2    94609
  3    94615    
  4    94617
  Name: SellTime, dtype: object