Skip to content

Instantly share code, notes, and snippets.

@bappi-d-great
Created August 20, 2014 10:10
Show Gist options
  • Save bappi-d-great/ce7f54c3af1568388011 to your computer and use it in GitHub Desktop.
Save bappi-d-great/ce7f54c3af1568388011 to your computer and use it in GitHub Desktop.
Show category description in WPMU classified listing
<?php
function the_dr_categories_home_theme( $echo = true, $atts = null ){
extract( shortcode_atts( array(
'style' => '', //list, grid
'lcats' => '', //
), $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
);
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 .= $category->description . '<hr>';
$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