• Hey everyone.

    I’m using the Categories Images plugin to try and show a thumbnail and a link to subcategories within any parent category page.

    I have created a child theme and am editing in the archive.php file within the child theme and I have this but it doesn’t produce any results (the image part).

    This is my code so far:

    
    	
    		<?php
    			$cat = get_category( get_query_var( 'cat' ) );
    			$cat_id = $cat->cat_ID;
    			$child_categories=get_categories(
        			array( 'parent' => $cat_id )
    			);
    		?>
    		
    		<ul>
    
    		<?php
    		foreach ( $child_categories as $child ) {
        		// Here I'm showing as a list...
        		echo '<li>';
        		
        	?>
        	
        	<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
        	
        	<?php
        	
        		echo '<a href="/'.$child ->slug.'">'.$child ->cat_name.'</a>';
        		echo '</li>';
    		}
    		?>
    		
    		</ul>
    
    	</div>
    

    And this is the documentation for the Categories Images plugin:

    http://zahlan.net/blog/2012/06/categories-images/

    I hope someone can show me the errors of my ways?

    Thanks!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,
    check
    <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />

    should be
    <img src="<?php echo z_taxonomy_image_url($child->term_id); ?>" />

    Regards

    • This reply was modified 8 years, 4 months ago by Diego Betto. Reason: formatting
    • This reply was modified 8 years, 4 months ago by Diego Betto.
    Thread Starter ajkelly4

    (@ajkelly4)

    Such a simple change… thank you!

    Thread Starter ajkelly4

    (@ajkelly4)

    Could I also ask… The line above:

    
    echo '<a href="/'.$child ->slug.'">'.$child ->cat_name.'</a>';
    

    returns /child-category as a url.

    How could I use what I have above to instead make it return:

    /parent-category/child-category

    ?

    Thank you!

    Moderator bcworkz

    (@bcworkz)

    echo '<a href="/'.$cat->slug.'/'.$child->slug.'">'.$child->cat_name.'</a>';

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Subcategory thumbnails within parent category’ is closed to new replies.