{"id":6176529,"date":"2015-05-28T16:32:20","date_gmt":"2015-05-28T16:32:20","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/shortcode-solution\/"},"modified":"2016-08-24T16:43:47","modified_gmt":"2016-08-24T16:43:47","slug":"shortcode-solution","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/shortcode-solution\/","title":{"rendered":"Shortcode Solution"},"content":{"rendered":"<p>I needed to be able to drop multiple author boxes onto a single page to show all the site&#8217;s authors. I like the look of this plugin, but it didn&#8217;t come with this functionality. I wanted to share how I did it in case anyone wants to do it.<\/p>\n<p><strong>Please note:<\/strong> if you upgrade the plugin you need to repeat the first step, unless the plugin author is willing to add this code to the core since it wouldn&#8217;t break any of the existing functionality.<\/p>\n<p><strong>Step 1: Modify \/core\/sabox_author_box.php<\/strong><\/p>\n<p>Change the function from this:<br \/>\n<code>function wpsabox_author_box( $saboxmeta = null ) {<\/code><\/p>\n<p>To this:<br \/>\n<code>function wpsabox_author_box( $saboxmeta = null, $authorid = NULL ) {<\/code><\/p>\n<p>And on the next line change this:<br \/>\n<code>if ( is_single() or is_author() or is_archive() ) {<\/code><\/p>\n<p>To this:<br \/>\n<code>if ( is_single() or is_author() or is_archive() or (is_page() and $authorid != NULL) ) {<\/code><\/p>\n<p>Then three more lines down change this:<br \/>\n<code>$author_id = $post-&gt;post_author;<\/code><\/p>\n<p>To this:<br \/>\n<code>$author_id = ($authorid == NULL) ? $post-&gt;post_author : $authorid;<\/code><\/p>\n<p><strong>Step 2: Create a shortcode in your theme&#8217;s functions.php<\/strong><\/p>\n<pre><code>if(function_exists(&#039;add_shortcode&#039;) &amp;&amp; function_exists(&#039;wpsabox_author_box&#039;)){\n\tfunction sabox_shortcode($atts){\n\t\textract(shortcode_atts(array(\n\t\t\t&#039;id&#039; =&gt; NULL,\n\t\t), $atts));\n\n\t\tob_start();\n\t\techo wpsabox_author_box(NULL, $id);\n\t\t$output = ob_get_contents();\n\t\tob_end_clean();\n\t\treturn $output;\n\t}\n\n\tadd_shortcode(&#039;authorimg&#039;, &#039;sabox_shortcode&#039;);\n}<\/code><\/pre>\n<p><strong>Usage: Place the shortcode in a post or page<\/strong><\/p>\n<p>[authorimg id=&#8221;THEAUTHORID&#8221;]<\/p>\n<p>Replace THEAUTHORID with the WordPress user ID of the author. So if your author has an id of 8, it would look like this:<\/p>\n<p>[authorimg id=&#8221;8&#8243;]<\/p>\n<p>You can place as many as you want on a page or post.<\/p>\n<p><strong>To the plugin author:<\/strong> would you mind making my changes to \/core\/sabox_author_box.php since it doesn&#8217;t affect existing functionality and will allow people who use this hack to update the plugin? Thanks.<\/p>\n<p>https:\/\/wordpress.org\/plugins\/simple-author-box\/<\/p>\n","protected":false},"template":"","class_list":["post-6176529","topic","type-topic","status-closed","hentry","topic-tag-shortcode"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6176529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/6176529\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=6176529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}