{"id":252,"date":"2012-07-13T22:29:56","date_gmt":"2012-07-13T14:29:56","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=252"},"modified":"2018-09-03T22:27:23","modified_gmt":"2018-09-03T14:27:23","slug":"displaying-post-author-information-in-your-wordpress-theme","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/displaying-post-author-information-in-your-wordpress-theme\/","title":{"rendered":"Displaying post author information in your WordPress theme"},"content":{"rendered":"<p>Every blog post has an author behind it. As web masters, we have the authority to decide whether to display some information about the author. <\/p>\n<p>Although I am the sole author of my blog, I feel that including some information about myself right after my posts can give my readers some form of assurance that they are reading something from a human.<\/p>\n<p>I present such information in the form of a little box:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/ph\/img\/blog\/posts\/about-me-at-end-of-blog-post.jpg\" alt=\"A brief description about me as at 13\/07\/2012\"\/><\/p>\n<h3>Storing relevant information with WordPress<\/h3>\n<p>Since I am the only writer for my blog, a straightforward approach to putting up information about myself could be hard coding them into <code>single.php<\/code>. However, this approach hurts scalability and maintainability. In the future, I could put up similar information at places other than <code>single.php<\/code>. Or I could invite others to post content in my blog in return for some visual space. <\/p>\n<h4>Storing authors' details with WordPress<\/h4>\n<p>Every author in a WordPress blog will use a <strong>user account<\/strong> to log into and write blog posts. With that, I use the edit profile page in the administration area of my blog to save some information about myself. <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/ph\/img\/blog\/posts\/wordpress-edit-user-profile-page.jpg\" alt=\"Wordpress edit profile page\"\/><\/p>\n<p>In this page, I filled up three pieces of information:<\/p>\n<ul>\n<li>A display name, which is different from my username.<\/li>\n<li>An email account which is registered with <a href=\"http:\/\/gravatar.com\" title=\"Link to Gravatar Home page\" target=\"_blank\">Gravatar<\/a> so that I can display my Gravatar photo.<\/li>\n<li>A paragraph about myself with some HTML formatting.<\/li>\n<\/ul>\n<h3>Displaying author's details<\/h3>\n<p>After I had saved the relevant information which I wish to display, I went on to identify the functions that will retrieve these information from the WordPress engine.<\/p>\n<h4>Outputting display name<\/h4>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php the_author_meta('display_name');?&gt;\r\n<\/pre>\n<p>I used the <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/the_author_meta\" title=\"Function Reference\/the author meta\"><code>the_author_meta<\/code><\/a> function with the string literal <code>'display_name'<\/code> to write my display name to the browser.<\/p>\n<h4>Outputting the Gravatar photo<\/h4>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php echo get_avatar(get_the_author_meta('user_email')); ?&gt;\r\n<\/pre>\n<p>I employed a two-step approach to outputting my Gravatar photo to the browser. <\/p>\n<ul>\n<li>I first get the email which I associate with my Gravatar account via the <code>get_the_author_meta<\/code> function, by passing it the string literal <code>'user_email'<\/code>. Note that unlike the <code>the_author_meta<\/code> function, the <code>get_the_author_meta<\/code> returns a string containing the requested information instead of directly writing it out to the browser.<\/li>\n<li>I then get the <code>img<\/code> tag for my Gravatar photo by passing the return value of <code>get_the_author_meta<\/code> into the <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/get_avatar\" title=\"Function Reference\/get avatar\" target=\"_blank\"><code>get_avatar<\/code><\/a> function. I then write the image tag to the browser via the <a href=\"http:\/\/php.net\/manual\/en\/function.echo.php\" title=\"PHP function reference for echo\" target=\"_blank\"><code>echo<\/code><\/a> function.<\/li>\n<\/ul>\n<h4>Outputting the biographical info<\/h4>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php the_author_meta('user_description');?&gt; \r\n<\/pre>\n<p>As with the outputting of the display name, I used the <code>the_author_meta<\/code> function with the string literal <code>'user_description'<\/code> to write my biographical information to the browser.<\/p>\n<h3>Formatting the information with HTML markup<\/h3>\n<p>With an idea of what functions to call for the information, I craft the entire HTML markup that will form the box. <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;div id=&quot;post-author&quot;&gt;\r\n    &lt;?php echo get_avatar(get_the_author_meta('user_email')); ?&gt;\r\n    &lt;h3&gt;About &lt;?php the_author_meta('display_name');?&gt;&lt;\/h3&gt;\r\n    &lt;p&gt;\r\n        &lt;?php the_author_meta('user_description');?&gt; \r\n    &lt;\/p&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>With the HTML markup in place, I then style the information with the following CSS rules.<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#post-author {\r\n  border: 3px solid #B8D6FF;\r\n  margin: 0 30px 0 17px;\r\n  min-height: 116px;\r\n}\r\n\r\n#post-author h3 {\r\n  color: #19447E;\r\n  font-size: 16px;\r\n  font-weight: bold;\r\n  margin: 10px 10px;\r\n}\r\n\r\n#post-author img {\r\n  border: 1px solid #B8D6FF;\r\n  display: block;\r\n  float: left;\r\n  margin: 10px;\r\n}\r\n\r\n#post-author p {\r\n  font-size: 14px;\r\n  text-align: left;\r\n  margin-right: 10px;\r\n}\r\n<\/pre>\n<h3>Some posts which may interest you<\/h3>\n<ul>\n<li><a href=\"http:\/\/www.techcoil.com\/blog\/make-your-php-webpage-loads-faster-by-aggregating-external-css-scripts\/\" title=\"Make your PHP webpage loads faster by aggregating external CSS scripts\" target=\"_blank\">Make your PHP webpage loads faster by aggregating external CSS scripts<\/a><\/li>\n<li><a href=\"http:\/\/www.techcoil.com\/blog\/php-codes-to-tell-browsers-to-open-the-download-dialog-box-for-users-to-download-a-file\/\" title=\"PHP codes to tell browsers to open the download dialog box for users to download a file\" target=\"_blank\">PHP codes to tell browsers to open the download dialog box for users to download a file<\/a><\/li>\n<li><a href=\"http:\/\/www.techcoil.com\/blog\/how-to-send-http-post-requests-and-http-get-requests-using-jquery\/\" title=\"How to send HTTP post requests and HTTP get requests using jQuery\" target=\"_blank\">How to send HTTP post requests and HTTP get requests using jQuery<\/a><\/li>\n<li><a href=\"http:\/\/www.techcoil.com\/blog\/code-segments-for-rendering-html-4-0-pages\/\" title=\"Code segments for rendering html 4.0 pages\" target=\"_blank\">Code segments for rendering html 4.0 pages<\/a><\/li>\n<li><a href=\"http:\/\/www.techcoil.com\/blog\/how-to-ensure-that-your-javascript-is-able-to-write-unicode-characters-from-external-javascript-files-to-your-html-contents\/\" title=\"How to ensure that your Javascript is able to write unicode characters from external Javascript files to your HTML contents\" target=\"_blank\">How to ensure that your Javascript is able to write unicode characters from external Javascript files to your HTML contents<\/a><\/li>\n<\/ul>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-44\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-44&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-44&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F252&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>Every blog post has an author behind it. As web masters, we have the authority to decide whether to display some information about the author. <\/p>\n<p>Although I am the sole author of my blog, I feel that including some information about myself right after my posts can give my readers some form of assurance that they are reading something from a human.<\/p>\n","protected":false},"author":1,"featured_media":1217,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[375],"tags":[13,5],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/WordPress-logo-on-black-background.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-44","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/252"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1217"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}