Created
March 10, 2023 09:45
-
-
Save rapanna/f54807aedf0b0a4a56beae3f4653204e to your computer and use it in GitHub Desktop.
shortcode
This file contains 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 | |
add_shortcode( 'shellers-top-category', 'shellers_top_category' ); | |
/** | |
* Show parent categories | |
* | |
* @author Radomir Panna | |
* @version 1.0.0 | |
* @param array $attr | |
* @return $output | |
*/ | |
function shellers_top_category ( $attr ) { | |
$output = ''; | |
$a = shortcode_atts( array( | |
'parents' => '0', | |
), $attr ); | |
$sheller_categories = get_terms('product_cat', array('parent' => esc_attr($a['parents']))); | |
if(!empty($sheller_categories)) { | |
$output .= '<ul class="topcategory">'; | |
foreach($sheller_categories as $sheller_category) { | |
$output .= '<li><a href="' . esc_url( get_term_link($sheller_category->term_id) ) . '">' . $sheller_category->name . '</a></li>'; | |
} | |
$output .= '</ul>'; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment