WordPress echo src for category image

I have added the ability to add featured images to post categories using a plugin called WP Custom Categories. I am trying to display a list of categories from a custom post type on a page but instead of displaying the title, I want to show the image.

To do this I have created a custom walker class for the Walker_Category which is changing the output of wp_list_categories.

Read More

My custom walker class looks like this in functions.php:

class WPQuestions_Walker extends Walker_Category {

function start_lvl(&$output, $depth=1, $args=array()) {  
    $output .= "n<ul class="product_cats">n";  
}  

function end_lvl(&$output, $depth=0, $args=array()) {  
    $output .= "</ul>n";  
}  

function start_el(&$output, $item, $depth=0, $args=array()) {
    // Category image
    if ( is_category() && function_exists('category_image_src')) {
$category_image = category_image_src( array( 'size' => 'full' ) , false );
} else {
$category_image = '';
} 

    //$output .= "<li class="item">".esc_attr( $item->name );
    $output .= "<div class="col-md-4 entry project">";
    $output .= "<img class="project_cat_image" src="";
    $output .= $category_image;
    $output .= ""/>";
}  

function end_el(&$output, $item, $depth=0, $args=array()) {  
    //$output .= "</li>n";
    $output .= "</div>";
}      

}

You will see the snippet of code I am using to try and grab the image is as follows:

// Category image
    if ( is_category() && function_exists('category_image_src')) {
$category_image = category_image_src( array( 'size' => 'full' ) , false );
} else {
$category_image = '';
}

However, no URL is being outputted in my html. What am I doing wrong here? Is there a better way to try and grab this image?

Related posts

Leave a Reply