Created
November 24, 2014 13:29
-
-
Save bappi-d-great/1fa73ff938aa7621ff73 to your computer and use it in GitHub Desktop.
WPMU Directory plugin shortcode to exclude Listing 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 | |
/* | |
* | |
* [dr_list_categories_with_exclude style="list" exclude="14"] where 14 is the listing category ID | |
* | |
*/ | |
function list_categories_sc_custom($atts, $content = null) | |
{ | |
extract(shortcode_atts(array( | |
'style' => '', //list, grid | |
'lcats' => '', // | |
'excelude' => '' | |
), $atts)); | |
if ($style == 'grid') $result = '<div class="dr_list_grid">'; | |
elseif ($style == 'list') $result = '<div class="dr_list">'; | |
else $result = "<div>"; | |
$result .= the_dr_categories_home_custom(false, $atts); | |
$result .= "</div><!--.dr_list-->"; | |
return $result; | |
} | |
add_shortcode('dr_list_categories_with_exclude', 'list_categories_sc_custom'); | |
function the_dr_categories_home_custom( $echo = true, $atts = null ){ | |
extract( shortcode_atts( array( | |
'style' => '', //list, grid | |
'lcats' => '', // | |
'excelude' => '' | |
), $atts ) ); | |
//get plugin options | |
$options = get_option( DR_OPTIONS_NAME ); | |
$cat_num = ( isset( $options['general']['count_cat'] ) && is_numeric( $options['general']['count_cat'] ) && 0 < $options['general']['count_cat'] ) ? $options['general']['count_cat'] : 10; | |
$sub_cat_num = ( isset( $options['general']['count_sub_cat'] ) && is_numeric( $options['general']['count_sub_cat'] ) && 0 < $options['general']['count_sub_cat'] ) ? $options['general']['count_sub_cat'] : 5; | |
$hide_empty_sub_cat = ( isset( $options['general']['hide_empty_sub_cat'] ) && is_numeric( $options['general']['hide_empty_sub_cat'] ) && 0 < $options['general']['hide_empty_sub_cat'] ) ? $options['general']['hide_empty_sub_cat'] : 0; | |
$taxonomies = array_values(get_taxonomies(array('object_type' => array('directory_listing'), 'hierarchical' => 1))); | |
$args = array( | |
'parent' => 0, | |
'orderby' => 'name', | |
'order' => 'ASC', | |
'hide_empty' => 0, | |
'hierarchical' => 1, | |
'number' => $cat_num, | |
'taxonomy' => $taxonomies, | |
'pad_counts' => 1, | |
'exclude' => $atts['exclude'], | |
); | |
if( !empty($lcats) ){ | |
$lcats = array_filter( explode(',', $lcats), 'is_numeric' ); | |
asort($lcats); | |
$lcats = implode(',', $lcats); | |
$args['include'] = $lcats; | |
} | |
$categories = get_categories( $args ); | |
$output = '<div id="dr_list_categories" class="listing_category" >' . "\n"; | |
$output .= "<ul>\n"; | |
foreach( $categories as $category ){ | |
$output .= "<li>\n"; | |
if( isset( $options['general']['display_parent_count'] ) && $options['general']['display_parent_count'] ) $parent_count = sprintf(' (%d)', $category->count ); | |
else $parent_count = ''; | |
$output .= sprintf('<h2><a href="%s" title="%s %s" >%s%s</a></h2>', | |
get_term_link( $category ), | |
esc_html__( 'View all posts in ', DR_TEXT_DOMAIN ), | |
$category->name, | |
$category->name, | |
$parent_count ); | |
$output .= '<div class="term-list">'; | |
$args = array( | |
'show_option_all' => '', | |
'orderby' => 'name', | |
'order' => 'ASC', | |
'style' => 'none', | |
'show_count' => ( !isset($options['general']['display_sub_count']) || $options['general']['display_sub_count'] == 1 ), | |
'hide_empty' => $hide_empty_sub_cat, | |
'use_desc_for_title' => 1, | |
'child_of' => $category->term_id, | |
'feed' => '', | |
'feed_type' => '', | |
'feed_image' => '', | |
'exclude' => '', | |
'exclude_tree' => '', | |
'hierarchical' => true, | |
'title_li' => '', | |
'show_option_none' => '', //sprintf('<span class="dr-empty">%s</span>', __('No categories', DR_TEXT_DOMAIN ) ), | |
'number' => $sub_cat_num, | |
'echo' => 0, | |
'depth' => 1, | |
'current_category' => 0, | |
'pad_counts' => 1, | |
'taxonomy' => $category->taxonomy, | |
'walker' => null | |
); | |
if( !empty($lcats) ) { | |
$args['include'] = $lcats; | |
} | |
$output .= wp_list_categories($args); | |
$output .= "</div><!-- .term-list -->\n"; | |
$output .= "</li>\n"; | |
} | |
$output .= "</ul>\n"; | |
$output .= "</div><!-- .dr_list_categories -->\n"; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment