{"id":6426,"date":"2016-02-04T10:46:28","date_gmt":"2016-02-04T15:46:28","guid":{"rendered":"https:\/\/themespress.ca\/?p=6426"},"modified":"2022-09-18T12:58:47","modified_gmt":"2022-09-18T16:58:47","slug":"display-a-wordpress-authors-links","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/display-a-wordpress-authors-links\/","title":{"rendered":"Display a WordPress Author&#8217;s Links"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Here&#8217;s a quick and easy tutorial to display posts published by your WordPress authors. Consult the <a title=\"Codex Author Templates\" href=\"http:\/\/codex.wordpress.org\/Author_Templates\" target=\"_blank\" rel=\"noopener\">Codex Author Templates<\/a>.<\/p>\n<p>There are two ways to go about it. Both are efficient methods of doing it, but the second one is cleaner and easier.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >First solution<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>This query will allow you to display posts from a WordPress author. <\/p>\n<p>If for example, you want to display your author&#8217;s ads, simply add this argument: post_type => ads.<\/p>\n<p>For the <code class=\"jscript string\">get_the_post_thumbnail<\/code>, we simply choose the size desired. You choose from thumbnail, medium or custom size with <a title=\"Fonction add_image_size\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/add_image_size\" target=\"_blank\" rel=\"noopener\"> add_image_size<\/a><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2776749\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-2776749\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ Fonction post reli&eacute;s author\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nfunction get_author_posts() {\nglobal $authordata, $post;\n\n\/\/ Nous creons une variable qui stocke tous les posts par auteur en excluant l&#039;article consult&eacute; sur la page en affichant en al&eacute;atoire et un certain nombre\n$authors_posts = get_posts( \narray( \n&#039;category__in&#039;            =&gt; wp_get_post_categories($post-&gt;ID), \n&#039;author&#039;                  =&gt; $authordata-&gt;ID, \n&#039;post__not_in&#039;            =&gt; array( $post-&gt;ID ), \n&#039;posts_per_page&#039;          =&gt; 6, \n&#039;orderby&#039;                 =&gt; &#039;rand&#039; ) );\n\n\/\/ Nous commencons a afficher nos resultats\n$output =&#039;&#039;; \nforeach ( $authors_posts as $authors_post ) { \/\/ Nous allons chercher le title du post \n\t$parent_title = get_the_title($authors_post-&gt;ID); \n\t$excerpt = get_the_excerpt($authors_post-&gt;ID); \n\t\/\/ Nous commencons a afficher nos resultats \n\t$output .= &#039;&#039;; \n\t$output .= get_the_post_thumbnail($authors_post-&gt;ID,&rsquo;thumbnail&rsquo;); \n\t$output .= &#039;&#039; . apply_filters( &lsquo;the_title&rsquo;, $authors_post-&gt;post_title, $authors_post-&gt;ID ) . &#039;&#039;; \n\t$output .= &#039;&#039;; \n} \n$output .= &#039;&#039;; \n\/\/ On retourne tous les r&eacute;sultats \nreturn $output; \n}\n?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You&#8217;ll notice that in the category__in =>  wp_get_post_categories($post->ID) query allows you to display post displayed in a category.<\/p>\n<p>For example, we will display this in the <strong>single.php<\/strong> or <strong>single-post-type.php<\/strong> template.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-8364868\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-8364868\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php echo get_author_posts(); ?&gt;<\/pre><\/div><h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >The second solution<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You&#8217;ll find the function below. It is easier to use given that it uses arguments in a table and returns results with the $authors_posts variable.<\/p>\n<p>You&#8217;ll also notice that we&#8217;re using a Post_type which matches the posts, but you can also use your own POST_TYPE and add additional arguments. <\/p>\n<p>The post__not_in => array( $post-&gt;ID ) allows users to exclude post or single post type of the current post given that we don&#8217;t want to see it in the linked posts.<\/p>\n<p>We could also add the category posts related to the author&#8217;s posts by using this argument: category => category_id. Simply replace category_id by your own category&#8217;s ID.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9352849\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-9352849\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">function get_theme_author_posts( $items = 1 ) {\nglobal $authordata, $post;\n$authors_posts = get_posts(\narray(\n&#039;author&#039; =&amp;gt; $authordata-&amp;gt;ID,\n&#039;post__not_in&#039; =&amp;gt; array( $post-&amp;gt;ID ),\n&#039;posts_per_page&#039; =&amp;gt; $items,\n&#039;post_type&#039; =&amp;gt; &#039;post&#039;\n)\n);\nreturn $authors_posts;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>This will be what we displayed in the <strong>single.php<\/strong> or <strong>single-post-type.php<\/strong>template. <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-7297001\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7297001\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">&lt;?php $related_posts = get_theme_author_posts(3); foreach( $related_posts as $post ) : setup_postdata( $post ); ?&gt;<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You&#8217;ll also see that default permalink is author.<\/p>\n<p>Ex : http:\/\/www.viamultimedia.ca\/<strong>author<\/strong>\/tony<\/p>\n<p>If you want to change the authors&#8217; permalink, simply use wp_rewrite.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-5047573\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-5047573\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ Fonction rewrite url author\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nadd_action(&#039;init&#039;, &#039;via_author_base&#039;);\nfunction via_author_base() {\nglobal $wp_rewrite;\n$author_slug = &#039;auteur&#039;; \/\/ change slug name\n$wp_rewrite-&amp;gt;author_base = $author_slug;\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>This will result in a new permalink slug.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Ex : http:\/\/www.viamultimedia.ca\/<strong>wp-authors<\/strong>\/tony<\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Finally, you can customize the CSS of your authors&#8217; posts.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"Here's a quick and easy tutorial to display posts published by your WordPress authors. Consult the Codex Author Templates. There are two ways to go about it. Both are efficient<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/display-a-wordpress-authors-links\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4488,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[326],"class_list":["post-6426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-users"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6426"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6426\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4488"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}