David Stockdale's Scrapcode

Author & Co-Author Links on Posts/Pages

After altering the “author.php” template to list any pages/posts authored or co-authored by an author the next step is to make links to these archives available everywhere on your website.

First create the “post_authors_post_links” shortcode to return the names of co-authors linked to their archive pages.

/**
 * Shortcode for getting coauthors.
 */
add_shortcode( 'post_authors_posts_links', 'post_authors_posts_links_shortcode' );
/**
 * Shortcode for getting coauthors.
 */
function post_authors_posts_links_shortcode(  ) {
	return coauthors_posts_links();
}

Then create the “post_date” shortcode to get the date the posts/page was posted.

function shortcode_post_published_date(){
 return get_the_date();
}
add_shortcode( 'post_date', 'shortcode_post_published_date' );

Next enable shortcode to function within widgets

add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');

After which you create the “authors” widget.

add_action( 'widgets_init', 'authors_widgets_init' );

function authors_widgets_init() {
    beans_register_widget_area( array(
        'name' => 'Authors',
        'id' => 'authors',
        'description' => 'Widgets in this area will be shown after posts and pages for the purpose of listing the co-authors and date of publishing.',
        'beans_type' => 'grid'
    ) );
}

Then you add the “beans_content_after_markup” action to display the “authors” widget after all beans content.

add_action( 'beans_content_after_markup', 'authors_widget_area' );

function authors_widget_area() {
 echo beans_widget_area( 'authors' );
}

Finally simply add this Custom HTML to the “Authors” widget:

[post_date] [post_authors_posts_links]

Unfortunately Co-Authors Plus seemingly causes a double/repeat of the “coauthors_posts_links” shortcode results to show up above whatever content it is placed below/after.

This means you might get the same list of co-authors on both the top and bottom of the page.

I solved this problem with the brutally simply solution of hiding everything and then just showing what I wanted to be shown.

This was done by adding the following CSS code to my style.

/**
 * Hides everything in beans_main (part 1 of hiding duplicate names caused by use of coauthors).
 */
body > div.tm-site > main > div > div > div {
	visibility: collapse;
}

/**
 * Un-hides only the actual content within beans_main (part 2 of hiding duplicate names caused by use of coauthors).
 */
#beans-content {
	visibility: visible!important;
}

/**
 * Un-hides and styles the text widget containing a the coauthors of a page/post (part 3 of hiding duplicate names caused by use of coauthors).
 */
body > div.tm-site > main > div > div > div:nth-child(1) .textwidget {
	display:inline!important;
	visibility:visible!important;
}

Leave a Reply