• I needed to be able to drop multiple author boxes onto a single page to show all the site’s authors. I like the look of this plugin, but it didn’t come with this functionality. I wanted to share how I did it in case anyone wants to do it.

    Please note: 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’t break any of the existing functionality.

    Step 1: Modify /core/sabox_author_box.php

    Change the function from this:
    function wpsabox_author_box( $saboxmeta = null ) {

    To this:
    function wpsabox_author_box( $saboxmeta = null, $authorid = NULL ) {

    And on the next line change this:
    if ( is_single() or is_author() or is_archive() ) {

    To this:
    if ( is_single() or is_author() or is_archive() or (is_page() and $authorid != NULL) ) {

    Then three more lines down change this:
    $author_id = $post->post_author;

    To this:
    $author_id = ($authorid == NULL) ? $post->post_author : $authorid;

    Step 2: Create a shortcode in your theme’s functions.php

    if(function_exists('add_shortcode') && function_exists('wpsabox_author_box')){
    	function sabox_shortcode($atts){
    		extract(shortcode_atts(array(
    			'id' => NULL,
    		), $atts));
    
    		ob_start();
    		echo wpsabox_author_box(NULL, $id);
    		$output = ob_get_contents();
    		ob_end_clean();
    		return $output;
    	}
    
    	add_shortcode('authorimg', 'sabox_shortcode');
    }

    Usage: Place the shortcode in a post or page

    [authorimg id=”THEAUTHORID”]

    Replace THEAUTHORID with the WordPress user ID of the author. So if your author has an id of 8, it would look like this:

    [authorimg id=”8″]

    You can place as many as you want on a page or post.

    To the plugin author: would you mind making my changes to /core/sabox_author_box.php since it doesn’t affect existing functionality and will allow people who use this hack to update the plugin? Thanks.

    https://www.ads-software.com/plugins/simple-author-box/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thanks for this, msumner!

    Was looking for exactly this.

    Only issue is that, while it does grab the correct author, image, and description, the social links are all the same (pointing to the person who created the page I believe). See what I mean here: https://theunlockr.com/about/

    Any fix by any chance?

    Nevermind, fixed it.

    I replaced this line under “// author box social icons” in the same file:

    $sabox_author_fields = get_the_author_meta( $sabox_social_id );

    with this:

    $sabox_author_fields = get_the_author_meta( $sabox_social_id, $author_id );

    Thanks again and hope that helps others with the issue.

    Second that on adding this all into the plugin files itself if the author doesn’t mind.

    Thanks for this!
    How would you do to create a shortcode to display the social icons of [author ID], and nothing more?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode Solution’ is closed to new replies.