• Resolved foxxa

    (@foxxa)


    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 category

    foreach( $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/

    https://www.ads-software.com/plugins/categories-images/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter foxxa

    (@foxxa)

    For clarification…

    First reference link: only the icons should appear under each Service, not the photos…

    —-

    Second reference link: the parent cat image should show up below the header nav / above the blue box.

    The subcat icons should show up under ‘Recommended Services.’

    Plugin Author Muhammad

    (@elzahlan)

    Ok, here is what I think would help you:

    You need to know how the plugin works, if you used the function z_taxonomy_image(); without any parameters the plugin will guess the current category or term and automatically displays the image of this category.

    So if you need to show only the current category image, in category-[slug].php file all you need to do is to call the plugin function without any parameters.

    But if you want to display list of the categories, parents or children in any file in your theme all you have to do is to use one of the loop examples in the plugin documentation here

    Hope I helped.

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Parent Category and Subcategories conflicts’ is closed to new replies.