Skip to content

Instantly share code, notes, and snippets.

@rapanna
Created March 10, 2023 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rapanna/f54807aedf0b0a4a56beae3f4653204e to your computer and use it in GitHub Desktop.
Save rapanna/f54807aedf0b0a4a56beae3f4653204e to your computer and use it in GitHub Desktop.
shortcode
<?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