Home › Forums › WoodMart support forum › Category Page Categories under title
Category Page Categories under title
- This topic has 6 replies, 2 voices, and was last updated 1 month, 3 weeks ago by
Luke Nielsen.
-
AuthorPosts
-
February 4, 2025 at 5:09 am #635141
bcasaleadersincParticipantOn 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.
-
This topic was modified 1 month, 3 weeks ago by
bcasaleadersinc.
Attachments:
You must be logged in to view attached files.February 4, 2025 at 5:22 am #635145
bcasaleadersincParticipantInteresting 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.February 4, 2025 at 5:24 am #635148
bcasaleadersincParticipantOr 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.February 4, 2025 at 5:27 am #635149
bcasaleadersincParticipantLooks like the problem is that thumbnail images are not all being accepted when chosen.
What are the requirements for thumbnail images?February 4, 2025 at 12:43 pm #635248
Luke NielsenKeymasterHello,
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.
Kind Regards
February 5, 2025 at 1:26 am #635449
bcasaleadersincParticipantThats lovely, thank you.
February 5, 2025 at 10:19 am #635494
Luke NielsenKeymasterHello,
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
-
This topic was modified 1 month, 3 weeks ago by
-
AuthorPosts
Tagged: category
The topic ‘Category Page Categories under title’ is closed to new replies.
- You must be logged in to create new topics. Login / Register