Author Bio Excerpt
Tento článek (nebo jeho část) je převzat z externího zdroje. Je tedy slušností jej uvést včetně případného autora.
When you like to show a short intro of the author bio of a post and not his complete bio. Use this code snippet to make an excerpt of the bio, with a link to the author page, where you can show the full bio.
Usage:
1 2 |
// Add this code snippet to the single.php file where you like to display the author bio excerpt. <br /> echo author_excerpt(); |
CODE SNIPPET:
1 2 3 4 5 6 7 8 9 10 11 12 |
// Paste the code below to the functions.php file inside the theme directory you're using. function author_excerpt (){ $word_limit = 20; // Limit the number of words $more_txt = 'read more about:'; // The read more text $txt_end = '...'; // Display text end $authorName = get_the_author(); $authorUrl = get_author_posts_url( get_the_author_meta('ID')); $authorDescription = explode(" ", get_the_author_meta('description')); $displayAuthorPageLink = count($authorDescription) > $word_limit ? $txt_end.' '.$more_txt.' <a href="'.$authorUrl.'">'.$authorName.'</a>' : '' ; $authorDescriptionShort = array_slice($authorDescription, 0, ($word_limit)); return (implode($authorDescriptionShort, ' ')).$displayAuthorPageLink; } |
Napsat komentář