Community Forums › Forums › Design Tips and Tricks › Adding custom taxonomy to archive page post meta
This topic contains 2 replies, has 1 voice, and was last updated by FireSamurai 4 months ago.
-
AuthorPosts
-
January 17, 2013 at 11:33 am #12657
Is anyone aware how to display a custom post type’s (cpt) taxonomy on an
archive-[cpt].phppage? I’ve tried numerous different things, but have come up short. The closest I can get to this is by filter the post meta, however,is_page_template()is not allowed within the loop…Here is the filter method that works with the exception of the
is_page_templateconditional tag./** Customize the post meta function for archive-news.php */ add_filter( 'genesis_post_meta', 'post_meta_filter' ); function post_meta_filter( $post_meta ) { if ( is_page_template( 'archive-news.php' ) ) { $news_taxonomy = get_the_term_list( $post->ID, 'news_category', 'Filed Under: ', ', ', '' ); $post_meta = $news_taxonomy . '[post_tags before="Tagged: "]'; return $post_meta; }}
My Websites: TheCookingDish.com | ChrisMower.com
Connect with me: Facebook | Pinterest | Twitter | Google +January 17, 2013 at 12:57 pm #12683I have also attempted moving the conditional out of the filter function in this way, but with no luck:
/** Customize the post meta function for archive-news.php */ function change_news_post_meta_filter() { if ( is_page_template( 'archive-news.php' ) ) { add_filter( 'genesis_post_meta', 'news_post_meta_filter' ); function news_post_meta_filter( $post_meta ) { $news_taxonomy = get_the_term_list( $post->ID, 'news_category', 'Blah Under: ', ', ', '' ); $post_meta = $news_taxonomy . '[post_tags before="Tagged: "]'; return $post_meta; } } }
My Websites: TheCookingDish.com | ChrisMower.com
Connect with me: Facebook | Pinterest | Twitter | Google +January 17, 2013 at 1:41 pm #12701Okay… feeling
a littletotally embarrassed here. It turns out after many attempts that I was in the wrong file; no wonder nothing I attempted worked. *facepalm*When I realized that, I went back to an earlier (and simpler) version and it’s working just fine. The following code will display the CPT’s categories on any page using
archive-[cpt].phppage template. Add this to yourarchive-[cpt].phppage template. You will need to replace ‘news_category’ with whatever you used when registering your taxonomy.add_filter( 'genesis_post_meta', 'news_post_meta_filter' ); function news_post_meta_filter( $post_meta ) { $news_taxonomy = get_the_term_list( $post->ID, 'news_category', 'Filed Under: ', ', ', '' ); $post_meta = $news_taxonomy . '[post_tags before="Tagged: "]'; return $post_meta; }
My Websites: TheCookingDish.com | ChrisMower.com
Connect with me: Facebook | Pinterest | Twitter | Google + -
AuthorPosts
You must be logged in to reply to this topic.