Skip to content

Instantly share code, notes, and snippets.

@sevenspark
Last active February 22, 2023 06:11
Show Gist options
  • Save sevenspark/2f329c60202a028c2866 to your computer and use it in GitHub Desktop.
Save sevenspark/2f329c60202a028c2866 to your computer and use it in GitHub Desktop.
UberMenu Dynamic Categories Shortcode
function ss_menu_terms( $atts ){
extract( shortcode_atts( array(
'tax' => 'category',
'display_count' => 'false',
'columns' => 5,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 'false',
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
//'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => 'true',
'child_of' => 0,
'get' => '',
'name__like' => '',
'pad_counts' => 'false',
'offset' => '',
'search' => '',
'cache_domain' => 'core'
), $atts ) );
$display_count = $display_count == 'true' ? true : false;
$hide_empty = $hide_empty == 'true' ? true : false;
$hierarchical = $hierarchical == 'false' ? false : true;
$pad_counts = $pad_counts == 'true' ? true : false;
if( strpos( $tax , ',' ) ) $tax = explode( ',' , $tax );
if( !is_array( $exclude ) ) $exclude = explode( ',' , $exclude );
if( !is_array( $exclude_tree ) ) $exclude_tree = explode( ',' , $exclude_tree );
if( !is_array( $include ) ) $include = explode( ',' , $include );
$term_args = compact(
'orderby' , 'order' , 'hide_empty' , 'exclude' ,
'exclude_tree' , 'include' , 'number' , 'slug' ,
'parent' , 'hierarchical' , 'child_of' , 'get' ,
'name__like' , 'pad_counts' , 'offset' ,
'search' , 'cache_domain' );
$terms = get_terms( $tax , $term_args );
$n = count( $terms );
$per_column = ceil( $n / $columns );
$html = '<div class="menu-terms menu-terms-col-'.$columns.'">';
$html.= '<ul class="menu-terms-column">';
foreach( $terms as $i => $term ){
$html.= '<li class="term-'.$term->term_id.' term-slug-'.$term->slug.' term-taxonomy-'.$term->taxonomy.'">';
$html.= '<a href="'.get_term_link($term).'">';
$html.= $term->name;
if( $display_count ) $html.= ' ('.$term->count. ')';
$html.= '</a></li>';
if( ($i+1) % $per_column == 0 ){
$html.= '</ul><ul class="menu-terms-column">';
}
}
$html.= '</ul></div>';
//umssd( $terms[0] );
return $html;
}
add_shortcode( 'menu-terms' , 'ss_menu_terms' );
#megaMenu ul.megaMenu .menu-terms-item{
width:100%;
-webkit-box-sizing:border-box;
-mox-box-sizing:border-box;
-o-box-sizing:border-box;
box-sizing:border-box;
}
#megaMenu ul.megaMenu .menu-terms{
margin-top:10px;
}
#megaMenu ul.megaMenu .menu-terms a{
text-decoration: none;
font-size:12px;
}
#megaMenu ul.megaMenu .menu-terms ul.menu-terms-column{
-webkit-box-sizing:border-box;
-mox-box-sizing:border-box;
-o-box-sizing:border-box;
box-sizing:border-box;
float:left;
margin:0;
padding-right:20px;
margin-bottom:20px;
list-style:none;
}
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-1 ul.menu-terms-column{ width: 100%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-2 ul.menu-terms-column{ width: 50%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-3 ul.menu-terms-column{ width: 33%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-4 ul.menu-terms-column{ width: 25%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-5 ul.menu-terms-column{ width: 20%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-6 ul.menu-terms-column{ width: 16%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-7 ul.menu-terms-column{ width: 14%; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-8 ul.menu-terms-column{ width: 12%; }
@media only screen and (max-width:767px) {
#megaMenu ul.megaMenu .menu-terms-item{ width:100% !important; }
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-1 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-2 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-3 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-4 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-5 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-6 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-7 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-8 ul.menu-terms-column{ width: 50%; }
}
@media only screen and (max-width:479px) {
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-1 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-2 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-3 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-4 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-5 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-6 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-7 ul.menu-terms-column,
#megaMenu ul.megaMenu .menu-terms.menu-terms-col-8 ul.menu-terms-column{ width: 100%; }
}
@tibebugoa
Copy link

good but too wide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment