WordPress.org

Ready to get started?Download WordPress

Forums

Current Author (67 posts)

  1. syncbox
    Member
    Posted 8 years ago #

    OK, I have a custom category template that I link to by passing the category and the author id

    a href="/category/crew?author=51"

    and I can get posts to show up. But what I also want to do is to dynamically get the author's profile information (profile, first name, last name, etc) and display it outside of the loop.

    How can I do that? I've looked at ALL the various links (all day long) and nothing quite comes to what I want, which is to be able to display both profile and posts for a specific author by passing the author_ID via a link. It seems like most of what I have read relates to the current user or finds the current author by login...

  2. Anonymous
    Unregistered
    Posted 8 years ago #

    Kafkaesqui wrote:
    "Here's all the author profile data you could access this way:

    $curauth->user_aim;
    $curauth->user_email;
    $curauth->user_firstname;
    $curauth->user_icq;
    $curauth->user_lastname;
    $curauth->user_level;
    $curauth->user_login;
    $curauth->user_msn;
    $curauth->user_nickname;
    $curauth->user_description;
    $curauth->user_url;
    $curauth->user_yim; "

    I'm fairly new to WP and very new to php. What syntax would I use for an if statement to check if any of these data items has a value, before echo it? Thanks

  3. tmm
    Member
    Posted 8 years ago #

    This is the way it worked on my blog:

    <?php if(isset($_GET['author_name'])) : $curauth = get_userdatabylogin($author_name);
    else : $curauth = get_userdata($author);
    endif;
    ?>
    <?php echo $curauth->user_firstname; ?> <?php echo $curauth->user_lastname; ?>
    <?php echo $curauth->user_description; ?>

    You should also take a look at Kaf's (http://szub.net/) "Get Author Profile" Plugin.

    Hope this helps

  4. greenveggy
    Member
    Posted 8 years ago #

    Hi, I was trying to override my default admin setting -> 2 posts displayed per page for the archive (by author) template.
    So I tried the get_posts command. The loop I tried does not work, the post_author=$curauth->ID is not working. Could you tell me what I did wrong please?

    Here's the code I used:

    <html>
    <body>
    <?php get_header(); ?>
    <div id="content" class="narrowcolumn">
    <!-- This sets the $curauth variable -->
    <?php
    if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($author_name);
    else :
    $curauth = get_userdata(intval($author));
    endif;
    ?>

    <h2>Posts by <?php echo $curauth->nickname; ?>:</h2>

    <!-- The Loop -->

      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    • " rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
      <?php the_title(); ?>
      ,
      <?php the_time('d M Y'); ?> in <?php the_category(', ');?>
    • <?php the_excerpt(); ?>

      <?php endwhile; else: ?>
      <?php _e('No posts by this author.'); ?>

      <?php endif; ?>
      <!-- End Loop -->

      <div class="navigation">
      <div class="alignleft"><?php posts_nav_link('','','« Previous Entries') ?></div>
      <div class="alignright"><?php posts_nav_link('','Next Entries »','') ?></div>

      </div>

    </div>

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    </body>
    </html>

  5. pramudita
    Member
    Posted 7 years ago #

    I need to display author name of post at blog's header(header.php).
    I don't know why functions/plugins posted here, did not work for my blog.

    Currently I use WP 2.0.3 and RevvedUp Theme. hosted at dreamhost.

    Any advice ?

  6. Chris_K
    Member
    Posted 7 years ago #

    My advice: Start a new thread. You'll get noticed.

  7. dharmarketing
    Member
    Posted 7 years ago #

    Here's how I got it running in my header (WP 2.0.5).

    By the way, I'll be releasing this in a new "AutoSEO" theme later in the week probably -- you can see it running already on my sister's site, http://www.atlantarealestateforum.com. Just working out some bugs.

    Back to business:

    ***all of the following takes place in header.php***

    For the title, you're going to have some conditionals, for instance:

    (Fingers crossed -- I've never tried to put code in a forum before...)


    <?php
    if ( is_single() )
    {
    ?>
    <title>
    <?php wp_title(' '); ?>
    <?php if(wp_title(' ', false)) { echo ' | '; } ?>
    <?php bloginfo('name'); ?>
    </title>
    <?php
    }
    else
    {
    if(is_home())
    { ?> <title><?php bloginfo('name'); ?> | <?php bloginfo('description'); ?> | <?php wp_title(); ?></title>
    <? }

    elseif (is_category(''))
    { ?> <title><?php single_cat_title(); ?> | <?php bloginfo('name'); ?></title>
    <?php }

    Now we're going to set up a new conditional ('elseif') for your author.php file, placing it somewhere after the above code but BEFORE your 'else' statement that ends your <title>-tag conditionals...

    ...and I'm sure there's a 'prettier' way to code this...


    elseif (is_author(''))
    {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if(isset($_GET['author_name'])) : $curauth = get_userdatabylogin($author_name);
    else : $curauth = get_userdata($author);
    endif;
    ?>
    <title><?php echo $curauth->display_name; ?> | Posts by author | <?php bloginfo('name'); ?></title>
    <?php }

    You can then use <?php echo $curauth->display_name; ?> elsewhere in the header -- for instance, in the AutoSEO theme, the breadcrumb-looking line above the logo is actually the <h1> headline, determined in header.php using conditionals based on what page it is. You don't have to query any more variables, just stick in your echo.

    Now... back to your author.php page...

    ***the following goes in author.php***

    You have to put this in the author.php page again, I'd recommend after the get_header call:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if(isset($_GET['author_name'])) : $curauth = get_userdatabylogin($author_name);
    else : $curauth = get_userdata($author);
    endif;
    ?>

    After that, to display the author's name or whatever, use this:
    <?php echo $curauth->display_name; ?>

    Hope that helps!

Topic Closed

This topic has been closed to new replies.

About this Topic