Current Author (67 posts)

  1. syncbox
    Posted 10 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
    Posted 10 years ago #

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

    $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
    Posted 10 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);
    <?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
    Posted 10 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:

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

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



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


  5. pramudita
    Posted 9 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
    Posted 9 years ago #

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

  7. dharmarketing
    Posted 9 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...)

    if ( is_single() )
    <?php wp_title(' '); ?>
    <?php if(wp_title(' ', false)) { echo ' | '; } ?>
    <?php bloginfo('name'); ?>
    { ?> <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);
    <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:

    $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);

    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