Skip to Content

post_categories()

Show the post categories.

PHP March 25, 2020

Usage

PHP
nebula()->post_categories($options)

Parameters

$options
(Optional) (Array) An array of options
Default: None

Parameter Notes

label
Whether to show the category “icon”, “text”, or not
Default: icon

linked
Whether to wrap the categories in a hyperlink
Default: true

show_uncategorized
Include the “Uncategorized” category
Default: true

force
Override the Customizer setting
Default: false

string
Return a string with no markup
Default: false

Request or provide clarification »

Demo


Using post_meta:
Using individual Nebula post meta functions with options:
Other Nebula meta functions:
  • Functions
  • No EXIF data found

Source File

Located in /libs/Functions.php on line 545.

1 Hook

Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

Filters
"nebula_post_categories_defaults"
Need a new filter hook? Request one here.

Actions
This function has no action hooks available. Request one?

PHP
    public function post_categories($options=array()){
        $defaults = apply_filters('nebula_post_categories_defaults', array(
            'id' => get_the_ID(),
            'label' => 'icon', //"icon" or "text"
            'linked' => true, //Link to category archive
            'show_uncategorized' => true, //Show "Uncategorized" category
            'force' => false,
            'string' => false, //Return a string with no markup
        ));

        $data = array_merge($defaults, $options);

        if ( get_theme_mod('post_categories', true) || $data['force'] ){
            $label = '';
            if ( $data['label'] === 'icon' ){
                $label = '<i class="nebula-post-categories-label fas fa-fw fa-bookmark"></i> ';
            } elseif ( $data['label'] === 'text' ){
                $label = '<span class="nebula-post-categories-label">' . __('Category', 'nebula') . '</span>';
            }

            if ( is_object_in_taxonomy(get_post_type(), 'category') ){
                $category_list = get_the_category_list(', ', '', $data['id']);

                if ( strip_tags($category_list) === 'Uncategorized' && !$data['show_uncategorized'] ){
                    return false;
                }

                if ( !$data['linked'] ){
                    $category_list = strip_tags($category_list);
                }

                if ( $data['string'] ){
                    return strip_tags($category_list);
                }

                return '<span class="posted-in meta-item post-categories">' . $label . $category_list . '</span>';
            }
        }
    }

Override

This function can not be short-circuited with an override filter. Request one?