Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rajucs/3f668ec03840f3ee10d4884eb83005ce to your computer and use it in GitHub Desktop.

Select an option

Save rajucs/3f668ec03840f3ee10d4884eb83005ce to your computer and use it in GitHub Desktop.
<?php
$taxonomyName = "product_cat";
//This gets top layer terms only. This is done by setting parent to 0.
$parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false));
echo '<ul>';
foreach ($parent_terms as $pterm) {
//show parent categories
echo '<li><a href="' . get_term_link($pterm->name, $taxonomyName) . '">' . $pterm->name . '</a></li>';
$thumbnail_id = get_woocommerce_term_meta($pterm->term_id, 'thumbnail_id', true);
// get the image URL for parent category
$image = wp_get_attachment_url($thumbnail_id);
// print the IMG HTML for parent category
echo "<img src='{$image}' alt='' width='400' height='400' />";
}
echo '</ul>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment