Support » Plugin: Post Content Shortcodes » Is there a way to show the Cataegory in the output list?

  • I would like to be able to help the user to distinguish between different categories, within a list of all posts.

    ie. I have two categories “Category1” and another “Category2”. Right now the list outputs:

    – Post 5
    – Post 4
    – Post 3
    – Post 2
    – Post 1

    Is there away to output the list like so to show the unique category for each individual post:

    – [Category1] Post 5
    – [Category2] Post 4
    – [Category1] Post 3
    – [Category1] Post 2
    – [Category2] Post 1

    ??

    Thanks

    https://wordpress.org/plugins/post-content-shortcodes/

Viewing 1 replies (of 1 total)
  • Plugin Author Curtiss Grymala

    (@cgrymala)

    Theoretically, you should be able to use the post-content-shortcodes-open-item filter to accomplish this. The code might look something like:

    add_filter( 'post-content-shortcodes-open-item', 'my_pcs_add_cat_to_title', 10, 3 );
    function my_pcs_add_cat_to_title( $output, $post_id, $atts ) {
        $cats = get_the_category( $post_id );
        if ( empty( $cats ) || ! is_array( $cats ) )
            return $output;
        $category = array_shift( $cats );
        return $output . '[' . $category->name . '] ';
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Is there a way to show the Cataegory in the output list?’ is closed to new replies.