[Support request] How do I display a Custom Taxonomy on my Single Posts

Home Forums Support How do I display a Custom Taxonomy on my Single Posts

This topic contains 8 replies, has 2 voices, and was last updated by  Tom 2 months, 2 weeks ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1193456

    Nates

    Hi

    I created a taxonomy called Topics, using Custom Post Type UI. On my single posts, I would to keep displaying the category/tag but also include the topics taxonomy.

    How do I achieve this please?

    Regards

    #1194051

    Tom Lead Developer

    Hi there,

    Try this:

    add_action( 'generate_post_meta_items', function( $item ) {
        $term_list = get_the_term_list( get_the_ID(), 'topic', '', ', ' );
    
        if ( 'topics' === $item && $term_list ) {
            printf( '<span class="tags-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ', // WPCS: XSS ok, sanitization ok.
                esc_html_x( 'Topics', 'Used before category names.', 'generatepress' ),
                $term_list,
                apply_filters( 'generate_inside_post_meta_item_output', '', 'topics' )
            );
        }
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array(
            'categories',
            'tags',
            'topics',
            'comments-link',
        );
    } );
    #1194315

    Nates

    Thanks, but it did not work. The CTX slug is ‘topic’

    
    add_action( 'generate_post_meta_items', function( $item ) 
    {
        $term_list = get_the_term_list( get_the_ID(), 'topic', '', ', ' );
    
        if ( 'topic' === $item && $term_list ) {
            printf( '<span class="tags-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ', // WPCS: XSS ok, sanitization ok.
                esc_html_x( 'Topics', 'Used before category names.', 'generatepress' ),
                $categories_list,
                apply_filters( 'generate_inside_post_meta_item_output', '', 'topic' )
            );
        }
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array(
            'categories',
            'tags',
            'topic',
            'comments-link',
        );
    } );
    
    
    #1194317

    Nates

    $term_list = the_terms( get_the_ID(), 'topic', '', ', ' );

    I made this change (the_terms instead of the_terms_list) and it now displays my topic x3 times on the single post… ?

    #1194784

    Tom Lead Developer
    #1194818

    Nates

    I did originally and never worked, I had to change topics to topic, then I tried the other stuff I mentioned to TRY and get it to work..

    #1195034

    Tom Lead Developer

    Did you try it again? I updated it after your last reply.

    #1195145

    Nates

    Thanks! It iss working.. How do I add an icon to the front though?

    #1195585

    Tom Lead Developer

    You can do this:

    add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
        if ( 'topic' === $item ) {
            return 'YOUR ICON ELEMENT HERE';
        }
    
        return $output;
    }, 10, 2 );
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.