Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need help with a function WordPress

  • SOLVED

Hi,

I am working on a site with the following theme (its attached as a zip). The theme has a author bio box at the end of each post, which is great and i like. The author box will show the author/user that created that post.

I have downloaded a somewhat popular plug in called " Co-Authors Plus" , that lets you use multiple authors for a post and it also lets you create guest authors. The guest authors are a special type of user that do not need a password, are easy to create and most importantly do not become registered users.

I need some help getting the guest author info to show on the theme’s author bio box whenever there is not a registered user as the main author of the post.

Here is the documentation, that shows how to achieve this (apparently the plug ins uses its own functions on top of Wordpress author’s functions).

This is the link for the plugin documentation.
https://vip.wordpress.com/documentation/incorporate-co-authors-plus-template-tags-into-your-theme

This is the link to the zip
href="https://www.dropbox.com/s/zlgw8rtc50vn8cx/Archive.zip?dl=0"

Answers (3)

2015-03-06

Romel Apuya answers:

on ur theme in templates/post-meta.php

replace this line

<?php echo vw_get_avatar( get_the_author_meta('user_email'), VW_CONST_AVATAR_SIZE_SMALL ); ?>
<a class="author-name author" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" title="<?php _e('View all posts by', 'envirra'); ?>
<?php the_author(); ?>" rel="author"><?php the_author(); ?></a>


with

<?php if ( function_exists( 'coauthors_posts_links' ) ) { ?>
$poster = get_the_author();
$author = coauthors( null, null, null, null, false );

<?php if ( 1 == count( get_coauthors( get_the_id() ) ) ){ ?>
<?php echo vw_get_avatar( the_author_meta('user_email'), VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php the_author_meta( 'display_name' ); ?><br />
<?php the_author_meta( 'user_email' ); ?><br />
<?php the_author_meta( 'description' ); ?><br />
<?php } else{ ?>
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ) : ?>
<?php echo vw_get_avatar( $coauthor->user_email, VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php echo $coauthor->display_name;?><br />
<?php echo $coauthor->user_email;?><br />
<?php echo $coauthor->description;?><br /><br />
<?php endforeach; ?>
<?php } ?>
<?php } else { ?>
<?php echo vw_get_avatar( get_the_author_meta('user_email'), VW_CONST_AVATAR_SIZE_SMALL ); ?>
<a class="author-name author" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" title="<?php _e('View all posts by', 'envirra'); ?>
<?php the_author(); ?>" rel="author"><?php the_author(); ?></a>
<?php } ?>


Romel Apuya comments:

sorry should be templates/post-box/post-box-meta.php


Romel Apuya comments:

<?php if ( function_exists( 'coauthors_posts_links' ) ) { ?>
<?php if ( 1 == count( get_coauthors( get_the_id() ) ) ){ ?>
<?php echo vw_get_avatar( the_author_meta('user_email'), VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php the_author_meta( 'display_name' ); ?><br />
<?php the_author_meta( 'user_email' ); ?><br />
<?php the_author_meta( 'description' ); ?><br />
<?php } else{ ?>
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ) : ?>
<?php echo vw_get_avatar( $coauthor->user_email, VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php echo $coauthor->display_name;?><br />
<?php echo $coauthor->user_email;?><br />
<?php echo $coauthor->description;?><br /><br />
<?php endforeach; ?>
<?php } ?>
<?php } else { ?>
<?php echo vw_get_avatar( get_the_author_meta('user_email'), VW_CONST_AVATAR_SIZE_SMALL ); ?>
<a class="author-name author" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" title="<?php _e('View all posts by', 'envirra'); ?>
<?php the_author(); ?>" rel="author"><?php the_author(); ?></a>
<?php } ?>


Romel Apuya comments:

Hi,

I have tested the code above and the file to edit really is in templates/about-author.php

i created guests author and posts, assign guest author to post.

but on some reason it always has the creator of the post on th co-author even if i removed the admin..

in what manner are you able to achieve this

I need some help getting the guest author info to show on the theme’s author bio box whenever there is not a registered user as the main author of the post.

if you want you can reach me on skype: rrapuya

cheers,

romel


Romel Apuya comments:

Hi,

Seems it was an error on my side.

copy this code on your neue/templates/about-author.php


<div class="vw-about-author-section vcard author">
<div class="vw-about-author">
<?php if ( function_exists( 'coauthors_posts_links' ) ) {
$co_auth = get_coauthors();
?>
<?php if ( 1 == count( get_coauthors( get_the_id() ) ) ){ ?>
<?php
if(($co_auth[0]->type)=='guest-author'){ ?>
<?php echo vw_get_avatar( $coauthor->user_email, VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php echo $co_auth[0]->display_name;?><br />
<?php echo $co_auth[0]->user_email;?><br />
<?php echo $co_auth[0]->description;?><br /><br />
<?php }else{ ?>
<?php echo vw_get_avatar( $coauthor->user_email, VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php echo $co_auth[0]->display_name;?><br />
<?php echo $co_auth[0]->user_email;?><br />
<?php echo $co_auth[0]->description;?><br /><br />
<?php } ?>
<?php } else{ ?>
<?php foreach( $co_auth as $coauthor ) : ?>
<?php echo vw_get_avatar( $coauthor->user_email, VW_CONST_AVATAR_SIZE_SMALL ); ?>
<?php echo $coauthor->display_name;?><br />
<?php echo $coauthor->user_email;?><br />
<?php echo $coauthor->description;?><br /><br />
<?php endforeach; ?>
<?php } ?>
<?php } else { ?>
<?php echo vw_get_avatar( get_the_author_meta('user_email'), VW_CONST_AVATAR_SIZE_SMALL ); ?>
<a class="author-name author" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" title="<?php _e('View all posts by', 'envirra'); ?>
<?php the_author(); ?>" rel="author"><?php the_author(); ?></a>
<?php } ?>
</div>
</div>


Romel Apuya comments:

with further testing and theme adaptation here is the fullcode


<?php if ( function_exists( 'coauthors_posts_links' ) ) {
$co_auth = get_coauthors();
?>
<?php if ( 1 == count( get_coauthors( get_the_id() ) ) ){ ?>
<?php
if(($co_auth[0]->type)=='guest-author'){ ?>
<div class="vw-about-author-section vcard author">
<a class="vw-author-avatar" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" title="<?php _e('View all posts by', 'envirra'); ?> <?php the_author(); ?>">
<?php echo vw_get_avatar( $co_auth->user_email, VW_CONST_AVATAR_SIZE_LARGE ); ?>
</a>
<div class="vw-about-author">
<h3 class="vw-author-name fn"><?php echo $co_auth[0]->display_name;?></h3>
<p class="vw-author-bio note"><?php echo $co_auth[0]->description;?></p>
<div class="vw-author-socials clearfix">
<?php vw_the_author_social_links(); ?>
</div>
</div>
</div>
<?php }else{ ?>
<div class="vw-about-author-section vcard author">
<?php vw_the_author_avatar(); ?>
<div class="vw-about-author">
<h3 class="vw-author-name fn"><?php echo $co_auth[0]->display_name;?></h3>
<p class="vw-author-bio note"><?php echo $co_auth[0]->description;?></p>
<div class="vw-author-socials clearfix">
<?php vw_the_author_social_links(); ?>
</div>
</div>
</div>
<?php } ?>
<?php } else{ ?>
<?php foreach( $co_auth as $coauthor ) : ?>
<div class="vw-about-author-section vcard author">
<a class="vw-author-avatar" href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>" title="<?php _e('View all posts by', 'envirra'); ?> <?php the_author(); ?>">
<?php echo vw_get_avatar( $coauthor->user_email, VW_CONST_AVATAR_SIZE_LARGE ); ?>
</a>
<div class="vw-about-author">
<h3 class="vw-author-name fn"><?php echo $coauthor->display_name;?></h3>
<p class="vw-author-bio note"><?php echo $coauthor->description;?></p>
<div class="vw-author-socials clearfix">
<?php vw_the_author_social_links(); ?>
</div>
</div>
</div>
<?php endforeach; ?>
<?php } ?>
<?php } else { ?>
<div class="vw-about-author-section vcard author">
<?php vw_the_author_avatar(); ?>
<div class="vw-about-author">
<?php $author = vw_get_current_author(); ?>
<h3 class="vw-author-name fn"><?php echo $author->display_name; ?></h3>
<p class="vw-author-bio note"><?php echo nl2br( $author->user_description ); ?></p>

<div class="vw-author-socials clearfix">
<?php vw_the_author_social_links(); ?>
</div>
</div>
</div>
<?php } ?>


Romel Apuya comments:

ok just download the updated theme [[LINK href="https://drive.google.com/file/d/0B-2HKYxTDa2AcWxXN1lvMW10V3M/view?usp=sharing"]]here[[/LINK]]


dipka comments:

You are sooo close, but there are two issues.

1) On top of the page the author is still the user.
2) In the bio box the photo that appears is not the guest author’s featured image. Also when you click on the image it take you to the user’s profile not the guest author. (this last part is not super necessary, im fine if when you clicl on the picture it take you nowhere.)


Romel Apuya comments:

ok [[LINK href="https://drive.google.com/file/d/0B-2HKYxTDa2AaWZ1WnJDLU5FNmc/view?usp=sharing"]]here [[/LINK]]an updated one


dipka comments:

1) On top of the page the author is still the user. (no change)
2) In the bio box the photo that appears is not the guest author’s featured image.(no change)
Also when you click on the image it take you to the user’s profile not the guest author.(working perfectly)


Romel Apuya comments:

which top of the page are you referring??

attached is a screenshot and [[LINK href="https://drive.google.com/file/d/0B-2HKYxTDa2ATndlQ3U1YUc1Rmc/view?usp=sharing"]]here link[[/LINK]] of the file

i re-uploaded in case that i might have uploaded the wrong one