Shortcode Solution
-
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.
- The topic ‘Shortcode Solution’ is closed to new replies.