How to display Byline term descriptions as author biographies.
-
It’s a common practice to append a brief biographical profile about an author at the end of an article. Here are some code snippets that model ways to do this.
As discussed in this thread, here is Matt’s (corrected) code for displaying byline descriptions in a list below a post:
<?php $terms = get_the_terms($post->ID, 'byline'); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo "<h6>About " . $term->name . "</h6>"; echo "<p>" . $term->description . "</p>"; } echo "</ul>"; } ?>
The following snippet works a little differently. It first checks if the actual user-author has a bio filled out in their user profile. If they do, it’s displayed. Then if there are any byline co-authors with bios, these are put into an array separated by a tag (or whatever you want) and then displayed. This is useful if you’re just using Byline for Co-Authors and still want to use the WP user-author.
<?php if(is_single()) : ?> <div class="entry-author-bio"> <!-- If Author is User with Bio, display it --> <?php if ( is_singular() && $author_bio = get_the_author_meta( 'description' ) ) : ?> <!-- Insert your code for displaying normal user-author bylines here. --> <?php endif; ?> <!-- Now get and display any guest-author bylines. --> <?php global $post; $terms = get_the_terms($post->id, 'byline'); $guest_author_bio = array(); foreach ($terms as $term) { $guest_author_bio[] = $term->description; } $guest_author_bio = join( "<br> ", $guest_author_bio); echo $guest_author_bio; ?> </div> <?php endif;>
- The topic ‘How to display Byline term descriptions as author biographies.’ is closed to new replies.