Professional Documents
Culture Documents
Tutorial Details
Program: WordPress Version (if applicable): 3.X Difficulty: Beginner Estimated Completion Time: 30 mins If you run a multi-author website, you may want to consider adding an author template to your website. Author templates help present more information about writers and make it easier for visitors to find other articles the author have written. In this post we will be breaking the author template down and showing you how you can improve it.
In plain English, WordPress first looks for templates specifically created for individual authors such as author-kevin.php or author-24.php (note: nicename is set to match the corresponding username). If no template has been specifically created for that author, WordPress will display the authors information using the author.php template (which is what we are looking at today). If no author template of any description can be found WordPress defaults to the archive.php template and then the index.php template (if no archive template exists).
wp.tutsplus.com/tutorials/howtocreateawordpressauthorspagetemplate/
1/7
11/1/12
1. <?php wp_list_authors('orderby=post_count&order=DESC&number=10'); ?> Display the top ten users in descending order.
Below you will see the full code for the Twenty Eleven author.php template: view plaincopy to clipboardprint? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. <?php<br> /**<br> * The template for displaying Author Archive pages.<br> *<br> * @package WordPress<br> * @subpackage Twenty_Eleven<br> * @since Twenty Eleven 1.0<br> */<br> <br> get_header(); ?><br> <br> <section id="primary"><br> <div id="content" role="main"><br> <br> <?php if ( have_posts() ) : ?><br> <br> <?php<br> /* Queue the first post, that way we know<br> * what author we're dealing with (if that is the case).<br> *<br> * We reset this later so we can run the loop<br> * properly with a call to rewind_posts().<br> */<br> the_post();<br> ?><br> <br> <header class="page-header"><br> <h1 class="page-title author"><?php printf( __( 'Author Archives: %s', 'twentyeleven' ), '<span class="vcard"> <a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( "ID" ) ) ) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . ' </span>' ); ?></h1><br> 29. </header><br> 30. <br>
wp.tutsplus.com/tutorials/howtocreateawordpressauthorspagetemplate/
2/7
11/1/12
31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89.
<?php<br> /* Since we called the_post() above, we need to<br> * rewind the loop back to the beginning that way<br> * we can run the loop properly, in full.<br> */<br> rewind_posts();<br> ?><br> <br> <?php twentyeleven_content_nav( 'nav-above' ); ?><br> <br> <?php<br> // If a user has filled out their description, show a bio on their entries.<br> if ( get_the_author_meta( 'description' ) ) : ?><br> <div id="author-info"><br> <div id="author-avatar"><br> <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyeleven_author_bio_avatar_size', 60 ) ); ?><br> </div><!-- #author-avatar --><br> <div id="author-description"><br> <h2><?php printf( __( 'About %s', 'twentyeleven' ), get_the_author() ); ?></h2><br> <?php the_author_meta( 'description' ); ?><br> </div><!-- #author-description --><br> </div><!-- #entry-author-info --><br> <?php endif; ?><br> <br> <?php /* Start the Loop */ ?><br> <?php while ( have_posts() ) : the_post(); ?><br> <br> <?php<br> /* Include the Post-Format-specific template for the content.<br> * If you want to overload this in a child theme then include a file<br> * called content-___.php (where ___ is the Post Format name) and that will be used instead.<br> */<br> get_template_part( 'content', get_post_format() );<br> ?><br> <br> <?php endwhile; ?><br> <br> <?php twentyeleven_content_nav( 'nav-below' ); ?><br> <br> <?php else : ?><br> <br> <article id="post-0" class="post no-results not-found"><br> <header class="entry-header"><br> <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1><br> </header><!-- .entry-header --><br> <br> <div class="entry-content"><br> <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ? ></p><br> <?php get_search_form(); ?><br> </div><!-- .entry-content --><br> </article><!-- #post-0 --><br> <br> <?php endif; ?><br> <br> </div><!-- #content --><br> </section><!-- #primary --><br> <br> <?php get_sidebar(); ?><br> <?php get_footer(); ?>
Dont worry if the above code is a bit overwhelming. We will be looking at the main part of this template (i.e. everything between <div id=content role=main> and </div><! #content > in a second. Once you break it down you will find its fairly straight forward.
11/1/12
Page Navigation
At the top and bottom of the author page you will see links to older and newer posts. Twenty Eleven displays these links using the twentyeleven_content_nav function. view plaincopy to clipboardprint? 1. <?php twentyeleven_content_nav( 'nav-above' ); ?> Passing the parameter nav-above through the function displays the top nav whilst nav-below shows the navigation links for the bottom of the page. view plaincopy to clipboardprint? 1. <?php twentyeleven_content_nav( 'nav-below' ); ?> Details of the twentyeleven_content_nav function can be found in the Twenty Eleven theme functions template (functions.php). The function uses previous_posts_link and next_posts_link to display navigation links and ensures that no navigation is shown at the top of the 1st page. It also styles the links; aligning older posts to the left and newer posts to the right. If you want to add navigation to your author template, you can either wrap a CSS division around the previous_posts_link and next_posts_link functions and style them or, if you prefer, use a navigation plugin like WP PageNavi to do the work for you.
wp.tutsplus.com/tutorials/howtocreateawordpressauthorspagetemplate/
4/7
11/1/12
wp.tutsplus.com/tutorials/howtocreateawordpressauthorspagetemplate/
5/7
11/1/12
<?php the_author_meta( jabber ); ?> Displays the authors Jabber / Google Talk contact info. <?php the_author_meta( aim ); ?> Displays the authors AIM contact info. <?php the_author_meta( yim ); ?> Displays the authors Yahoo messenger contact info. <?php the_author_meta( user_level ); ?> Displays the authors user level (e.g. admin are level 10, subscribers are level 0). <?php the_author_meta( user_firstname ); ?> Displays the authors first name. <?php the_author_meta( user_lastname ); ?> Displays the authors last name. <?php the_author_meta( user_description ); ?> Displays the authors bio. <?php the_author_meta( rich_editing ); ?> Displays true if the author is using the visual editor and false if they have disabled it. <?php the_author_meta( comment_shortcuts ); ?> Displays true if the author has keyboard shortcuts enabled and false if they are not. <?php the_author_meta( admin_color ); ?> Displays the colour scheme the author has chosen for the admin area (classic for blue and fresh for grey). <?php the_author_meta( ID ); ?> Displays the authors ID. As we saw before, most basic author templates simply display the authors gravatar on one side and the authors bio on the other. You could easily spice this up with some CSS. For example, you could place an information box down one side showing the users contact information (email, Google talk etc), another showing the users full name and website address.
Conclusion
By improving your author.php template and displaying more information about authors you will give them more exposure and make it easier for readers to find out more about them. The template itself is fairly easy to modify once you get used to it. If your theme doesnt have an author.php template, the best thing to do is to copy another template such as page.php or archive.php and remove all the code from the content area i.e. keep the code at the top and bottom that shapes your design but remove all the code that isnt needed for the author page. Once you have done so, you should be able to easily create your own author.php template using this article and the author.php templates from the default themes Twenty Ten and Twenty Eleven as
wp.tutsplus.com/tutorials/howtocreateawordpressauthorspagetemplate/
6/7
11/1/12
Tags: about wordpressauthor templatehow to wordpresshow to wordpress websiteTutorialwhy wordpressword presswordpresswordpress 3wordpress blogwordpress for freewordpress how towordpress ofwordpress sitewordpress templatewordpress thatwordpress themeswordpress tutorialwordpress websitewordpress wordpress
By Kevin Muldoon
Kevin Muldoon is a webmaster and blogger who has been working online since 2000. His labour of love is WordPress Mods; a blog which focuses on WordPress themes, plugins, tutorials, resources, news and views. He also blogs regularly on his personal blog Kevin Muldoon about WordPress, blogging, useful onlines and services and making a living online.
wp.tutsplus.com/tutorials/howtocreateawordpressauthorspagetemplate/
7/7