Created
April 28, 2017 11:57
-
-
Save dasbairagya/0e5275db39e4fbe2a8e9b8692a76c5d6 to your computer and use it in GitHub Desktop.
Get the image,title and link of the parent term of product_cat taxonomy in woocommerce for creating the slide in home page with parent category.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $pterms = get_terms( array( | |
| 'taxonomy' => 'product_cat', | |
| 'parent' => 0 | |
| ) ); | |
| // echo '<pre>'; | |
| // var_dump($terms); | |
| foreach ($pterms as $myterm) { | |
| $term_link = get_term_link( $myterm ); | |
| $thumbnail_id = get_woocommerce_term_meta($myterm->term_id, 'thumbnail_id', true); | |
| $url = wp_get_attachment_url($thumbnail_id);//print the image | |
| $link = esc_url( $term_link );//print the link | |
| $name = $myterm->name;//print the name of the parent term | |
| // var_dump($url); | |
| ?> | |
| //your html code here | |
| <?php } ?>//end for each |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get all the categories and and subcategories you can use the below code....
<?php
$taxonomy = 'product_cat';
$orderby = 'field';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$all_categories = get_categories( $args );
echo "
";
foreach ($all_categories as $cat){
$term_link = get_term_link( $cat );
$link = esc_url( $term_link );
?>