Community Forums › Forums › Archived Forums › General Discussion › Display taxonomy description with Genesis shortcode
- This topic has 3 replies, 2 voices, and was last updated 12 years ago by
asterbird.
-
AuthorPosts
-
February 7, 2013 at 9:52 pm #18847
asterbird
MemberI have a custom taxonomy called 'attractions' with description field that normally doesn't show up on the frontend.
How do I display this?
I am using this Genesis shortcode in my theme's functions.php to display the taxonomy:
add_filter( 'genesis_post_meta', 'display_attractions_taxonomy' ); function display_attractions_taxonomy($post_meta) { $post_meta = '[post_terms before="Nearby Attractions: " taxonomy="attractions"]'; return $post_meta; }
Now how do I display the description along with it? I scoured the WP / Genesis forums, but can't figure out what I'm looking for. Any tips in the right direction are greatly appreciated!
February 8, 2013 at 2:53 am #18886vajrasar
MemberRead this, it may help you -
http://wpmu.org/how-to-display-your-wordpress-category-description-in-your-theme/
I make WordPress websites using Genesis Framework.
February 8, 2013 at 8:06 am #18921asterbird
Member@vajrasar, thanks! that was a great article, but I'm not sure if it works for custom taxonomies.
I am able to display the description nicely using the following code in my theme functions.php file.
/** * Sarah Edit - Customize the post meta function */ add_filter( 'genesis_post_meta', 'sarah_attractions_meta' ); function sarah_attractions_meta( $mix_venue ) { $terms = get_terms( "attractions" ); $count = count($terms); if ( $count > 0 ) { echo "Attractions Near " . get_the_title(); // post title for heading foreach ( $terms as $term ) { echo "<li>"; // taxonomy title with custom link to its single page echo "<a href='" . home_url() . "/attractions/" . $term->slug . "' title='See " . $term->name . " - an attraction nearby'>" . $term->name . "</a>"; echo "<br>"; echo "<span>" . $term->description . "</span>"; echo "</li>"; } } }
However, this displays all the attractions, not just the ones associated with the post. Maybe I should do a loop? I'm not sure how to do that.
February 8, 2013 at 9:32 am #18933asterbird
MemberThis works now. I found the code here, and customized it.
Now it echos the list of terms (for a taxonomy called attractions) associated with the post.
add_filter( 'genesis_post_meta', 'sarah_attractions_meta' ); function sarah_attractions_meta( ) { $terms = get_the_terms( $post->ID, 'attractions' ); if ( $terms && ! is_wp_error( $terms ) ) : $attraction_terms = array(); echo "<h4>Attractions Near " . get_the_title() . "</h4>"; foreach ( $terms as $term ) { echo '<li><a href="' . get_term_link($term->slug, 'attractions') . '">' . $term->name . '</a></li>'; echo '<li>' . $term->description . '</li>'; } $attractions = join( ", ", $attraction_terms ); endif; }
-
AuthorPosts
- The topic ‘Display taxonomy description with Genesis shortcode’ is closed to new replies.