WordPress.org

Ready to get started?Download WordPress

Forums

Co-Authors Plus
[resolved] Template Tags for Website URL and Custom Fields (4 posts)

  1. webmistress666
    Member
    Posted 11 months ago #

    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>
                    </ul>
                  </div>
                <?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!

    http://wordpress.org/extend/plugins/co-authors-plus/

  2. webmistress666
    Member
    Posted 11 months ago #

    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!

    Works:

    <!-- 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.

  3. webmistress666
    Member
    Posted 11 months ago #

    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: http://vip.wordpress.com/documentation/add-guest-bylines-to-your-content-with-co-authors-plus/#incorporating-new-profile-fields

    ^ It was pretty easy.

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

  4. webmistress666
    Member
    Posted 11 months ago #

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

    <?php
    //  Get the user's REAL WordPress ID by matching up email
        $get_user = get_user_by('email',$coauthor->user_email);
          if($get_user)
          {
             $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;
        }
    ?>

Reply

You must log in to post.

About this Plugin

About this Topic