- This topic has 8 replies, 2 voices, and was last updated 5 years, 6 months ago by
Tom.
-
AuthorPosts
-
March 12, 2020 at 10:56 pm #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
March 13, 2020 at 9:49 am #1194051Tom
Lead DeveloperLead DeveloperHi 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', 'post-navigation', ); } );
March 13, 2020 at 9:13 pm #1194315Nates
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', ); } );
March 13, 2020 at 9:18 pm #1194317Nates
$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… ?
March 14, 2020 at 8:07 am #1194784Tom
Lead DeveloperLead DeveloperCan you try the updated code above?: https://generatepress.com/forums/topic/how-do-i-display-a-custom-taxonomy-on-my-single-posts/#post-1194051
March 14, 2020 at 8:46 am #1194818Nates
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..
March 14, 2020 at 3:59 pm #1195034Tom
Lead DeveloperLead DeveloperDid you try it again? I updated it after your last reply.
March 14, 2020 at 8:46 pm #1195145Nates
Thanks! It iss working.. How do I add an icon to the front though?
March 15, 2020 at 8:05 am #1195585Tom
Lead DeveloperLead DeveloperYou 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 );
-
AuthorPosts
- You must be logged in to reply to this topic.