Support » Plugin: Co-Authors Plus » Template Tags for Website URL and Custom Fields

  • Resolved webmistress666


    I’ve spent the last hour trying to figure out how to get the extra fields and the website URL into my single.php. I’ve tried $coauthor->website, $coauthor->url, $coauthor->user_website, $coauthor->user_url, and nothing shows up, ever.

    <?php $coauthors = get_coauthors(); ?>
                <?php foreach( $coauthors as $coauthor ): ?>
                  <div class="details">
                    <?php $author_id = get_userdata( $coauthor->ID );
                    $author_site = get_userdata( $coauthor->user_url );
                    <?php echo get_avatar( $coauthor->user_email, '80' ); ?>
                    <ul class="authorinfo">
                      <li class="name vcard author"><strong class="fn"><a href="<?php echo get_author_posts_url($coauthor->ID); ?>"><?php echo $coauthor->display_name; ?></a></strong></li>
                      <li class="url"><?php echo $author_site; ?></li>
                <?php endforeach; ?>

    Same for my custom fields, which work great on the backend, but $coauthor->twitter, for instance, is no joy.

    What am I doing wrong?

    And is there by any chance a list of template tags, aside from opening up template-tags.php and sifting through it? All it seems to have are mostly functions for displaying author names and links, but I see nothing for website URL or custom fields. I couldn’t find documentation on either the WP plugin page or in the readme. Just that one post on your website about changing functions.php, which doesn’t apply to my theme at all.

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • It’s now clear to me that author post/archive links are only working halfway.

    EDITED TO ADD: Found the right one for author archive link, finally.

    So, for the people who will inevitably come along needing template tag enlightenment, a running tally!


    <!-- Avatar: -->
             <?php echo get_avatar( $coauthor->user_email, '80' ); ?>
    <!-- Username: -->
             <?php echo $coauthor->display_name; ?>
    <!-- Post Archive URL: -->
             <?php echo get_author_posts_url($coauthor->ID,$coauthor->user_nicename); ?>

    And that’s it so far. Will update if I find more.

    Ah, got it! It was the “get_userdata()” that was messing it up. It is not needed.

    These work:

    <!-- Website URL: -->
                 <?php echo $coauthor->website; ?>
    <!-- Custom Field: -->
                 <?php echo $coauthor->[field key]; ?>

    For reference, you can find out how to add custom profile fields by going here:

    ^ It was pretty easy.

    I’ll mark this as resolved, but if I find new tags, I’ll add them here.

    To print out the formal WordPress User Role (Subscriber, Author, Editor, Admin, etc):

    //  Get the user's REAL WordPress ID by matching up email
        $get_user = get_user_by('email',$coauthor->user_email);
             $wp_user_id = $get_user->ID;
    //  Get the user by their real ID, thus allowing us access
    //  to their official info
        $user = new WP_User( $wp_user_id );
    // Run through all different user roles and find the one that
    // matches our user ID and print the role
        if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
          foreach ( $user->roles as $role )
          echo $role;
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Template Tags for Website URL and Custom Fields’ is closed to new replies.