Skip to Content
Menu

post_type()

Show the post type metadata.

PHP December 9, 2020

Usage

PHP
nebula()->post_type($icon)

Parameters

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

Parameter Notes

Option parameters include:

icon (mixed)
True for default icons, False to disable icons, or a string of class names to be used on an <i> tag.
Default: true

linked (boolean)
True links to the post type archive, false does not link
Default: false

Request or provide clarification »

Demo


Using post_meta:
Using individual Nebula post meta functions with options:
  • Posted in PHP by
  • Modified on
  • Custom Format:
Other Nebula meta functions:
  • Function
  • No EXIF data found
Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

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

    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_type_defaults"
    Need a new filter hook? Request one here.

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

    Note: This function contains 1 to-do comment.

    PHP
            public function post_type($options=array()){
                $defaults = apply_filters('nebula_post_type_defaults', array(
                    'icon' => true, //True for generic defaults, false to disable icon, or string of class name(s) for icon.
                    'linked' => false //True links output to the post type archive page
                ));
                $data = array_merge($defaults, $options);
                $post_icon_img = false;
    
                if ( get_theme_mod('search_result_post_types', true) ){
                    global $wp_post_types;
                    $post_type = get_post_type();
                    $post_type_labels = get_post_type_object( $post_type )->labels;
    
                    if ( $data['icon'] ){
                        $post_icon = $wp_post_types[$post_type]->menu_icon;
                        $post_icon_img = '<i class="fa-solid fa-thumbtack"></i>';
    
                        if ( !empty($post_icon) ){
                            $post_icon_img = '<img src="' . $post_icon . '" style="width: 16px; height: 16px;" loading="lazy" />';
    
                            if ( strpos('dashicons-', $post_icon) >= 0 ){ //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8
                                $post_icon_img = '<i class="dashicons-before ' . $post_icon . '"></i>';
                            }
                        }
    
                        if ( gettype($data['icon']) === 'string' && $data['icon'] !== '' ){
                            $post_icon_img = '<i class="' . esc_html($data['icon']) . '"></i>';
                        }elseif ( $post_type === 'post' ){
                            $post_icon_img = '<i class="fa-solid fa-fw fa-thumbtack"></i>';
                        } elseif ( $post_type === 'page' ){
                            $post_icon_img = '<i class="fa-solid fa-fw fa-file-alt"></i>';
                        }
                    }
    
                    if ( $data['linked'] ){
                        return '<span class="meta-item post-type"><a href="' . esc_url(get_post_type_archive_link($post_type)) . '" title="See all ' . $post_type_labels->name . '">' . $post_icon_img . esc_html($post_type_labels->singular_name) . '</a></span>';
                    }
    
                    return '<span class="meta-item post-type">' . $post_icon_img . esc_html($post_type_labels->singular_name) . '</span>';
                }
            }
    

    Override

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