Function Reference: geodir_sc_cpt_categories_widget

Summary

The CPT categories widget shortcode.

Description

This implements the functionality of the CPT categories widget shortcode for displaying
all geodirectory categories.

Parameters

$atts
(array) (required) {
Attributes of the shortcode. @type string $title The title of the widget displayed. @type string $post_type Post type of listing. @type bool $hide_empty Hide empty categories? Default empty. @type bool $show_count Show category count? Default empty. @type bool $hide_icon Hide category icon? Default empty. @type bool $cpt_left Show CPT on same line? Default empty. @type string $sort_by Categories sort by. ‘az’ or ‘count’. @type string|int $max_count Max no of sub-categories count. @type string|int $max_level Max level of sub-categories depth. @type bool $no_cpt_filter Disable filter current viewing post type. @type bool $no_cat_filter Disable filter current viewing category. @type string $before_widget HTML content to prepend to each widget’s HTML output. @type string $after_widget HTML content to append to each widget’s HTML output. @type string $before_title HTML content to prepend to the widget title when displayed. @type string $after_title HTML content to append to the widget title when displayed. }.

Default: is a closing h3 element
$content
(string) (required) The enclosed content. Optional.

Default: None

Return Values

(string)
  • HTML content to display CPT categories.

Change Log

Since: 1.5.5

1.6.6 New parameters $no_cpt_filter &no_cat_filter added.

Source File

geodir_sc_cpt_categories_widget() is located in geodirectory_shortcodes.php [Line: 1420]

Source Code

function geodir_sc_cpt_categories_widget($atts, $content = '') {
    $defaults = array(
        'title' => '',
        'post_type' => '', // NULL for all
        'hide_empty' => '',
        'show_count' => '',
        'hide_icon' => '',
        'cpt_left' => '',
        'sort_by' => 'count',
        'max_count' => 'all',
        'max_level' => '1',
        'no_cpt_filter' => '',
        'no_cat_filter' => '',
        'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ); $params = shortcode_atts($defaults, $atts); /** * Validate our incoming params */ // Make sure we have an array $params['post_type'] = !is_array($params['post_type']) && trim($params['post_type']) != '' ? explode(',', trim($params['post_type'])) : array(); // Validate the checkboxes used on the widget $params['hide_empty'] = gdsc_to_bool_val($params['hide_empty']); $params['show_count'] = gdsc_to_bool_val($params['show_count']); $params['hide_icon'] = gdsc_to_bool_val($params['hide_icon']); $params['cpt_left'] = gdsc_to_bool_val($params['cpt_left']); if ($params['max_count'] != 'all') { $params['max_count'] = absint($params['max_count']); } if ($params['max_level'] != 'all') { $params['max_level'] = absint($params['max_level']); } $params['no_cpt_filter'] = gdsc_to_bool_val($params['no_cpt_filter']); $params['no_cat_filter'] = gdsc_to_bool_val($params['no_cat_filter']); $params['sort_by'] = $params['sort_by'] == 'az' ? 'az' : 'count'; ob_start(); the_widget('geodir_cpt_categories_widget', $params, $params); $output = ob_get_contents(); ob_end_clean(); return $output; }