Skip to content

Instantly share code, notes, and snippets.

@dikiyforester
Created September 23, 2018 07:36
Show Gist options
  • Save dikiyforester/ed9ea804159a095dd244cff64b8d1126 to your computer and use it in GitHub Desktop.
Save dikiyforester/ed9ea804159a095dd244cff64b8d1126 to your computer and use it in GitHub Desktop.
Appends the listing sub categories mega menu to the category menu item.
<?php
/**
* Appends the listing sub categories mega menu to the category menu item.
*
* @param string $item_output The menu item's starting HTML output.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param array $args An array of wp_nav_menu() arguments.
*/
function va_sub_category_mega_menu( $item_output, $item, $depth, $args ) {
// Must be a page and in the secondary menu location.
if ( VA_LISTING_CATEGORY !== $item->object || 'secondary' != $args->theme_location ) {
return $item_output;
}
$defaults = array(
'child_of' => $item->object_id,
'menu_cols' => 3, // AppThemes custom.
'cat_parent_count' => true,
'cat_child_count' => true,
'taxonomy' => VA_LISTING_CATEGORY,
'app_pad_counts' => true, // AppThemes custom. Used in 'app-term-counts' feature.
'column_wrapper' => '%s',
'main_list_wrapper' => '%s',
'main_item_wrapper' => '<div class="parent-cat-wrap column column-block"><div class="parent-cat cat-item-%1$d"><a href="%2$s">%4$s%5$s</a></div><!-- .parent-cat -->%6$s' . "\r\n</div><!-- .parent-cat-wrap -->\r\n",
'sub_list_wrapper' => '<div class="sub-cat-list">%s' . "</div>\r\n",
'sub_item_wrapper' => '<div class="cat-item cat-item-%1$d"><a href="%2$s">%4$s%5$s</a>%6$s' . "</div>\r\n",
'count_wrapper' => ' <span class="cat-item-count label">%d</span>',
'nocats_wrapper' => '<div class="sub-cat-list"><div class="cat-item">%s' . "</div>\r\n</div>\r\n",
);
$categories_list = appthemes_categories_list( $defaults, array(
'app_pad_counts' => $defaults['app_pad_counts'],
'child_of' => ! empty( $defaults['child_of'] ) ? $defaults['child_of'] : 0,
) );
if ( ! empty( $categories_list) ) {
$item_output .= sprintf(
apply_filters( 'va_category_mega_menu', '<ul class="listing-cats listing-cats-dropdown"><div class="cat-column row collapse small-up-1 medium-up-2 large-up-3">%s</div></ul>' ),
$categories_list
);
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'va_sub_category_mega_menu', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment