Home Forums General Issues List categories with extra fields Reply To: List categories with extra fields

  • Alrightie then.. your code is extremely overdoing it!

    You’ll want something like this:

    $args = array( 'hide_empty' => '0');
    $categories = get_categories($args);
    	echo '<ul>';
    	foreach($categories as $category) {
    		echo '<li>';
    		$image = get_field('nameofimagefield', 'category_'.$category->term_id);
    		echo '<img src="' . $image . ' />'; //change depending on the return value of the image field
    		echo '<span class="cat-title">' . $category->name . '</span>';
    		echo '<span class="cat-subtitle">' . get_field('nameofsubtitlefield', 'category_'.$category->term_id) . '</span>';
    		echo '<span class="cat-description">' . $category->description . '</span>';
    		echo '</li>';
    	echo '</ul>';

    dont forget to change the fieldnames