For us, when we query something like this:
new WP_Query([ 'orderby' => 'post_views', 'author' => $co_author_ID ]);
It won’t work. It shows no results. It works only with the main author.
Thank you,
Cuong Tran
]]><?php if ( function_exists( 'coauthors_posts_links' ) ) {
coauthors_posts_links();
} else {
the_author_posts_link();
} ?>
This outputs the author(s) of a post with their name(s) and a link to each individual’s archive of other posts on the site. Great!
For example, the meta section of a post will display:
“Post written by: Author1Name and Author2Name”
However, I want to add a photo/avatar next to each name to result in something like”
“Post written by: [Author1Photo] Author1Name and [Author2Photo] Author2Name”
I’ve attempted reading through the docs at https://docs.wpvip.com/technical-references/plugins/incorporate-co-authors-plus-template-tags-into-your-theme/ and have tried ‘Example #1’ at https://bekarice.com/adding-co-authors-plus-support-theme/ – but nothing I’ve tried has really worked.
One important note, I AM wishing to maintain the way that ‘coauthors_posts_links’ adds the ‘between’ and ‘betweenLast’ separators (adding in commas and/or an “and” between the names).
Any help or guidance is greatly appreciated
]]>This function uses global authordata, does this plugin extend that or have its own global I can glob onto?
function xxx_get_related_author_posts() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
if ( ! empty( $authors_posts ) ) {
$output = '';
}
foreach ( $authors_posts as $authors_post ) {
$output .= '<div><a href="' . get_permalink( $authors_post->ID ) . '" class="d-flex"><i class="far fa-newspaper"></i> ' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></div>';
}
return $output;
wp_reset_postdata();
}
Thanks
]]>Here’s an example of it working properly:
correct link
The code below is supposed to work like this: for each author, check if they are NOT an administrator. If they are not an administrator, display their bio information (picture, name, description, etc.). If they ARE an administrator, display the basic Immigration Team Info (from the correct link above).
For some reason, when there are multiple authors, it doesn’t display properly. But when the only author is an administrator, it DOES work properly. Any advice would be appreciated!
My Code:
<?php
if ( !has_category('i-am') ) {
echo '
<section class="author-content">
<hr>
<h2 class="cta">For more information, please contact:</h2>
';
if ( function_exists( 'coauthors_posts_links' ) ) {
global $post;
foreach( get_coauthors() as $coauthor ):
$authorID = $coauthor->ID;
$authorName = $coauthor->user_firstname . " " . $coauthor->user_lastname;
$authorFname = $coauthor->user_firstname;
$authorPicLoc = get_user_meta($authorID, 'shr_pic', true);
$authorPicture = wp_get_attachment_url($authorPicLoc);
$authorEmail = $coauthor->user_email;
$authorDescription = $coauthor->description;
$authorPosts = get_author_posts_url($authorID);
$authorFullBio = $coauthor->user_url;
$authorLinkedIn = $coauthor->linkedin; // outputs the linkedin url
$authorRole = get_author_role($authorID);
if ($authorRole != 'administrator') { ?>
<div class="author-item">
<img src="<?php echo $authorPicture;?>" alt="<?php echo $authorFname;?>'s headshot" />
<div class="author-info">
<h3 class="author-name"><?php echo $authorName;?></h3>
<p class="author-description"><?php echo $authorDescription;?></p>
<ul class="social-media">
<li><a href="<?php echo $authorPosts;?>">All Posts</a></li>
<li><a href="<?php echo $authorFullBio;?>" target="_blank">Full Bio</a></li>
<li><a href="mailto:<?php echo $authorEmail;?>">Email</a></li>
<?php if ( $authorLinkedIn != '' ){
echo '<li><a href="'.$authorLinkedIn.'" target="_blank">LinkedIn</a></li>';
};?>
</ul>
</div>
</div> <?php
}
elseif ( $authorRole = 'administrator' ) { ?>
<div class="author-item">
<img src="/wp-content/uploads/2015/02/Favicon.jpg" alt="Buchanan Ampersand" />
<div class="author-info">
<h3 class="author-name">Buchanan Immigration Team</h3>
<ul class="social-media">
<li><a href="<?php echo $authorPosts;?>">All Posts</a></li>
<li><a href="/contact">Contact Us</a></li>
</ul>
</div>
</div> <?php
}
endforeach;
}
echo '<hr></section>';
}
?>
]]>I did a summary of different pages with a while loop and call children of pages when they have some with a foreach, and I call the coauthors for each of them as I did in the single pages, but when there is more than one author, I just can see the first of them :
<ul id="home-slider-nav">
<?php $my_query = new WP_Query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post();
$posts = get_field('connexe_article_new');
?>
<li class="separator-h">
<h5 class="separator-h"><?php if(!$posts): ?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><?php else: ?><?php the_title() ?><?php endif ?></h5>
<?php if($posts):
$total = count($posts); ?>
<ol>
<?php foreach($posts as $key=>$post):
setup_postdata($post);
?>
<li<?php if(($key+1)!=$total){ echo ' class="separator-h"';}elseif(($key+1)==$total){ echo ' style="padding:0"';} ?>>
<h6 class="no-c"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<p class="cat">par <?php echo coauthors(', ',', ', null,null,false); ?></p>
</li>
<?php endforeach; ?>
</ol>
<?php else: ?>
<div>
<?php echo'<p class="separator-h no-c cat"> par <span>'.coauthors(', ',', ', null,null,false).'</span></p>'; ?>
<p class="cat"><b><?php echo get_first_category(); ?></b><span class="excerpt separator-l"><?php echo get_the_excerpt(); ?></span></p>
</div>
<?php wp_reset_postdata();
endif;
?>
</li>
<?php endwhile;
wp_reset_postdata(); // Restore global post data stomped by the_post().
} // if ($my_query)
?>
</ul>
]]><?php
$author_info_box = esc_attr( journo_edge_options()->getOptionValue( 'blog_author_info' ) );
$author_info_email = esc_attr( journo_edge_options()->getOptionValue( 'blog_author_info_email' ) );
$author_id = esc_attr( get_the_author_meta( 'ID' ) );
$social_networks = journo_edge_core_plugin_installed() ? journo_edge_get_user_custom_fields() : false;
$display_author_social = journo_edge_options()->getOptionValue( 'blog_single_author_social' ) === 'no' ? false : true;
?>
<?php if ( $author_info_box === 'yes') {
?>
<div class="edgtf-author-description">
<div class="edgtf-author-description-inner">
<div class="edgtf-author-description-content">
<div class="edgtf-author-description-image">
<a itemprop="url" href="<?php echo esc_url( get_author_posts_url( $author_id ) ); ?>" title="<?php the_title_attribute(); ?>">
<?php echo journo_edge_kses_img( get_avatar( get_the_author_meta( 'ID' ), 192 ) ); ?>
</a>
</div>
<div class="edgtf-author-description-text-holder">
<h4 class="edgtf-author-name vcard author">
<a itemprop="url" href="<?php echo esc_url( get_author_posts_url( $author_id ) ); ?>" title="<?php the_title_attribute(); ?>">
<span class="fn">
<?php
if ( get_the_author_meta( 'first_name' ) != "" || get_the_author_meta( 'last_name' ) != "" ) {
echo esc_html( get_the_author_meta( 'first_name' ) ) . " " . esc_html( get_the_author_meta( 'last_name' ) );
} else {
echo esc_html( get_the_author_meta( 'display_name' ) );
}
?>
</span>
</a>
</h4>
<?php if ( get_the_author_meta( 'description' ) != "" ) { ?>
<div class="edgtf-author-text">
<p itemprop="description"><?php echo wp_kses_post( get_the_author_meta( 'description' ) ); ?></p>
</div>
<?php } ?>
<?php if ( $author_info_email === 'yes' && is_email( get_the_author_meta( 'email' ) ) ) { ?>
<p itemprop="email" class="edgtf-author-email"><?php echo sanitize_email( get_the_author_meta( 'email' ) ); ?></p>
<?php } ?>
<?php if ( $display_author_social ) { ?>
<?php if ( is_array( $social_networks ) && count( $social_networks ) ) { ?>
<div class="edgtf-author-social-icons clearfix">
<?php foreach ( $social_networks as $network ) { ?>
<a itemprop="url" href="<?php echo esc_attr( $network['link'] ) ?>" target="_blank">
<?php echo journo_edge_icon_collections()->renderIcon( $network['class'], 'font_elegant' ); ?>
</a>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
</div>
<?php } ?>
]]>My expansion of Daniel’s code is:
/**
* Co-authors in RSS and other feeds
* /wp-includes/feed-rss2.php uses the_author(), so we selectively filter the_author value
*/
function db_coauthors_in_rss( $the_author ) {
if ( !is_feed() || !function_exists( 'coauthors') ){
#return coauthors__echo( null, null, null, null, false );
return $the_author;
}
else{
#return "hey hey hey";
return coauthors( null, null, null, null, false );
}
}
add_filter( 'the_author', 'db_coauthors_in_rss');
I’ll post any updates here; https://warrengroom.com/wordpress-help/co-authors-wordpress-rss-feeds/
I hope that this helps. Thanks, Daniel
Here is the code that creates the title (from Twentyfifteen, which I’m customizing):
elseif ( is_author() ) {
$author_id = intval( get_query_var(‘author’) );
$title = sprintf( $args[‘authortitle’], get_bloginfo(‘name’), $args[‘separator’], get_the_author_meta( ‘display_name’, $author_id ) );
$href = get_author_feed_link( $author_id );
I have a page using a custom template where I want to list all authors with their image and description, and also show a link to their posts page, but I can’t find a proper way to do that.
]]>