Display taxonomy description with Genesis shortcode

Community Forums Forums General Discussion Display taxonomy description with Genesis shortcode

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  asterbird 1 year, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #18847

    asterbird
    Participant
    Post count: 101

    I 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:

    [php]
    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;
    }
    [/php]

    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!

    #18886

    Vajrasar Goswami
    Participant
    Post count: 157
    #18921

    asterbird
    Participant
    Post count: 101

    @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.

    [php]
    /**
    * 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>";
    }
    }
    }
    [/php]

    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.

    #18933

    asterbird
    Participant
    Post count: 101

    This 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.

    [php]

    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;
    }

    [/php]

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Display taxonomy description with Genesis shortcode’ is closed to new replies.