Parent Category and Subcategories conflicts
-
Hello,
I know this has been addressed several times, but I’m still struggling to get the individual images to show up for the parent category and subcategories.
What’s happening:
I have several category-[slug].php templates with posts assigned to each one. Those posts are also assigned to subcategories. I have separate images uploaded for the parents and subcategories under Posts > Categories.(Code trials below all placed inside the loop)
I used the below code on the first category-[slug].php and it worked perfect:
<?php foreach (get_the_category() as $cat) : ?>
<?php z_taxonomy_image($cat->term_id); ?>
<?php endforeach; ?>I tried both the code above and below on the second category-[slug].php, and all of the parent category images, plus the current subcategory images, show on this template. The same thing happens on the first category-[slug].php template:
<?php foreach (get_categories() as $cat) : ?>
<?php z_taxonomy_image($cat->term_id); ?>
<?php endforeach; ?>Here’s what I currently have in category-[slug].php (based on pablovic’s post). None of the category images show up on the current category page for this one, but the parents and subcat images do show up on the first category-[slug].php:
<?php //for this category on an archive page, get the ID
$thisID = get_query_var(‘cat’);
$get_children_cats = array( ‘parent’ => $thisID ); //get children of this parent using thisID variable
$child_cats = get_the_category( $get_children_cats ); //get children of this parent categoryforeach( $child_cats as $child_cat ){
$childID = $child_cat->cat_ID; //for each child category, get the ID
if (function_exists(‘z_taxonomy_image’)) z_taxonomy_image( $child_cat->cat_ID ); //for each child cat, show cat image} ?>
Instead of what pbalovic had, I only need for the images to show, so I condensed it.
Reference links:
https://www.foxxwork.com/testing/trestles/category/services/
https://www.foxxwork.com/testing/trestles/category/ideas-for-entrepreneurs/
- The topic ‘Parent Category and Subcategories conflicts’ is closed to new replies.