- This topic has 8 replies, 2 voices, and was last updated 4 years, 10 months ago by
Tom.
-
AuthorPosts
-
May 7, 2018 at 12:37 pm #570004
dale
Howdy!
I am using the Custom Post Type UI plugin to create custom taxonomies for several websites. For the website linked here, the custom taxonomy types are Format, Genre, and Pay Rate, and each has their own set of taxonomies that I add to organize the posts. For example, Genre has “adventure”, “sci fi”, “romance”, and so forth as possible taxonomies.
How can I display the custom taxonomy type and “tags” in post meta? I definitely would like to display it on individual posts in the meta section (along with tags and categories). It’s less important to display them with post experts on the front page of the blog, but it would be nice to have that option too.
(And if you recommend a different plugin or code for custom taxonomies, let me know. I’ve only installed Custom Post Type UI on one site so far.)
Thanks!
GeneratePress 2.1.1GP Premium 1.6.2May 7, 2018 at 8:31 pm #570222Tom
Lead DeveloperLead DeveloperHi there,
So right now you’re displaying categories and tags, and you want to include your custom taxonomy terms after the tags?
Let me know ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 8, 2018 at 1:38 pm #570935dale
No, I want to display them as “format: blah blah blah” “genre: yadda yadda” and so forth. Their own thing, like tags and categories meta are their own things.
Did that make sense?
May 8, 2018 at 8:58 pm #571097Tom
Lead DeveloperLead DeveloperSomewhat complex, but you could try something like this:
add_action( 'generate_after_entry_content', 'tu_add_custom_tax_terms', 50 ); function tu_add_custom_tax_terms() { $taxonomies = array( 'post_tag' => 'Tags', 'category' => 'Categories', ); echo '<footer class="entry-meta">'; foreach ( $taxonomies as $id => $name ) { $term_list = get_the_term_list( get_the_ID(), $id, '', ', ' ); if ( $term_list ) { echo '<div class="taxonomy">'; echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', ', ' ); echo '</div>'; } } echo '</footer>'; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 9, 2018 at 3:53 am #571284dale
Thanks! For some reason, commas aren’t appearing between each term. Do I need to add something else? This is the code I used:
add_action( 'generate_after_entry_content', 'tu_add_custom_tax_terms', 50 ); function tu_add_custom_tax_terms() { $taxonomies = array( 'post_tag' => 'Tags', 'category' => 'Categories', 'genres' => 'Genres', 'format' => 'Format', 'payment' => 'Payment', ); echo '<footer class="entry-meta">'; foreach ( $taxonomies as $id => $name ) { echo '<div class="taxonomy">'; echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', '', '' ); echo '</div>'; } echo '</footer>'; }
You can see an example of how it generated at the bottom of https://www.dalecameronlowry.com/submission-call-cosmic-roots-eldritch-shores-june/
Also, to remove/hide the taxonomy (for example tags) when no terms are added, would I add an if/then line under
echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', '', '' );
Thanks so much!
May 9, 2018 at 4:06 am #571290dale
P.S. to add this via GP hooks, would I do it as:
<?php {
?>
add_action(‘tu_add_custom_tax_terms’, 50 );
function tu_add_custom_tax_terms() {
$taxonomies = array(
‘post_tag’ => ‘Tags’,
‘category’ => ‘Categories’,
‘genres’ => ‘Genres’,
‘format’ => ‘Format’,
‘payment’ => ‘Payment’,);
echo ‘<footer class=”entry-meta”>’;
foreach ( $taxonomies as $id => $name ) {
echo ‘‘;
echo $name . ‘: ‘ . get_the_term_list( get_the_ID(), $id, ”, ”, ” );
echo ‘‘;
}echo ‘</footer>’;
}
<?php }
?>May 9, 2018 at 8:43 am #571580Tom
Lead DeveloperLead DeveloperLooks like you removed the comma from the code I provided.
This is what it should be:
get_the_term_list( get_the_ID(), $id, '', ', ' );
This is what you have:
get_the_term_list( get_the_ID(), $id, '', '', '' );
I just edited the code above so they should only display if terms exist: https://generatepress.com/forums/topic/display-meta-for-custom-taxonomies/#post-571097
That code looks good for GP Hooks ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 9, 2018 at 10:31 am #571661dale
Thank you! It works great when added to functions php.
For some reason I couldn’t get it to work in GP hooks. I used:
<?php if ( in_category( 'for-writers' ) && is_single() ) { ?> add_action( 'tu_add_custom_tax_terms', 50 ); function tu_add_custom_tax_terms() { $taxonomies = array( 'post_tag' => 'Tags', 'category' => 'Categories', ); echo '<footer class="entry-meta">'; foreach ( $taxonomies as $id => $name ) { $term_list = get_the_term_list( get_the_ID(), $id, '', ', ' ); if ( $term_list ) { echo '<div class="taxonomy">'; echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', ', ' ); echo '</div>'; } } echo '</footer>'; } <?php } ?>
Did I make an error?
May 9, 2018 at 8:34 pm #571990Tom
Lead DeveloperLead DeveloperIt would need to look like this in GP Hooks:
<?php if ( in_category( 'for-writers' ) && is_single() ) : ?> $taxonomies = array( 'post_tag' => 'Tags', 'category' => 'Categories', ); echo '<footer class="entry-meta">'; foreach ( $taxonomies as $id => $name ) { $term_list = get_the_term_list( get_the_ID(), $id, '', ', ' ); if ( $term_list ) { echo '<div class="taxonomy">'; echo $name . ': ' . get_the_term_list( get_the_ID(), $id, '', ', ' ); echo '</div>'; } } echo '</footer>'; <?php endif; ?>
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.