Home Forums WoodMart support forum Category Page Categories under title

Category Page Categories under title

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #635141

    bcasaleadersinc
    Participant

    On the Category Page, I would Like the under the category title to show the child categories for that category.

    If there are no child categories, do not show any at all.

    If that is unable,

    I am trying to display categories, and I am having trouble getting category images to appear?
    I am using this code snippet:
    function display_child_categories() {
    if (is_product_category()) {
    $term = get_queried_object();
    $parent_id = $term->term_id;

    $args = array(
    ‘taxonomy’ => ‘product_cat’,
    ‘parent’ => $parent_id,
    ‘hide_empty’ => false,
    );

    $child_categories = get_terms($args);

    if (!empty($child_categories)) {
    echo ‘<div class=”child-categories-grid”>’;

    foreach ($child_categories as $child) {
    // Attempt to retrieve the WoodMart-specific category image
    $image = ”;
    if (function_exists(‘woodmart_get_category_image’)) {
    $image = woodmart_get_category_image($child->term_id);
    }

    // If no image is found, use the WooCommerce placeholder
    if (!$image) {
    $image = wc_placeholder_img_src();
    }

    echo ‘<div class=”category-item”>’;
    echo ‘term_id) . ‘”>’;
    echo ‘name) . ‘” />’;
    echo ‘<span class=”category-name”>’ . esc_html($child->name) . ‘</span>’;
    echo ‘
    ‘;
    echo ‘</div>’;
    }

    echo ‘</div>’;
    }
    }
    }
    add_action(‘woocommerce_before_shop_loop’, ‘display_child_categories’, 5);

    But the category images are not appearing, just the default woocommerce image.

    Attachments:
    You must be logged in to view attached files.
    #635145

    bcasaleadersinc
    Participant

    Interesting to note, it looks like it works, but not that deep into child categories.

    For example
    In Furniture > Bedrooms, the child categories show up (see attachment)

    But when you go one level deeper to Furniture > Bedrooms > Beds, the images do not show up

    Attachments:
    You must be logged in to view attached files.
    #635148

    bcasaleadersinc
    Participant

    Or it has something to do with the way the images are applied.
    Maybe those other images are working because the categories were imported from another site, but when trying to add images to categories using Product >Categories > Edit category, its not working.

    #635149

    bcasaleadersinc
    Participant

    Looks like the problem is that thumbnail images are not all being accepted when chosen.
    What are the requirements for thumbnail images?

    #635248

    Luke Nielsen
    Keymaster

    Hello,

    Remove that custom code and navigate to Theme Settings -> product archive -> Page title -> enable the “Show current category ancestors” option, clear the cache and check how it works.

    https://prnt.sc/Gs_wTPsxZiQd

    Kind Regards

    #635449

    bcasaleadersinc
    Participant

    Thats lovely, thank you.

    #635494

    Luke Nielsen
    Keymaster

    Hello,

    You’re very welcome!

    I’m glad the solution worked for you. If you need any further assistance, feel free to reach out.

    Kind Regards

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Category Page Categories under title’ is closed to new replies.