• Resolved jWill88

    (@jwill88)


    Hi,

    I have this function with is working fine, because i will list subcategories in category page, if they exist.

    function add_subcategory_list() {
    
    if( is_category() ) {
        $cat_id = get_query_var('cat');
        $cat_ancestors = array();
        $cat_ancestors[] = $cat_id;
        do {
        $cat_id = get_category($cat_id);
        $cat_id = $cat_id->parent;
        $cat_ancestors[] = $cat_id; }
        while ($cat_id);
        $cat_ancestors = array_reverse( $cat_ancestors );
        $top_cat = $cat_ancestors[1];
    wp_list_categories('title_li=&hide_empty=0&show_option_none=&child_of=' . $top_cat);
    }
    
     }

    How can I implement the images?

    Thanks!

    https://wordpress.org/plugins/categories-images/

Viewing 1 replies (of 1 total)
  • Plugin Author Zahlan

    (@elzahlan)

    Hey jWill88

    I think you should use get_categories instead of wp_list_categories, for example:

    function add_subcategory_list() {
        if( is_category() ) {
            $cat_id = get_query_var('cat');
            $cat_ancestors = array();
            $cat_ancestors[] = $cat_id;
            do {
            $cat_id = get_category($cat_id);
            $cat_id = $cat_id->parent;
            $cat_ancestors[] = $cat_id; }
            while ($cat_id);
            $cat_ancestors = array_reverse( $cat_ancestors );
            $top_cat = $cat_ancestors[1];
    
            $html = '<ul>';
            foreach (get_categories('title_li=&hide_empty=0&show_option_none=&child_of=' . $top_cat) as $cat) {
                $html .= '<li><img src="'.z_taxonomy_image_url($cat->term_id).'" /><a href="'.get_category_link($cat->term_id).'">'.$cat->cat_name.'</a></li>';
            }
            $html .= '</ul>';
            echo $html;
        }
     }

    hope I helped

Viewing 1 replies (of 1 total)

The topic ‘Display images with wp_list_categories’ is closed to new replies.