WordPress.org

Ready to get started?Download WordPress

Forums

How to call the_author_description(); for a specific author ID (5 posts)

  1. alsosara
    Member
    Posted 7 years ago #

    Hello all,

    I would like to set up a page on my blog that has descriptive bios for each author. I'd like it to call the <?php the_author_description(); ?> for each person, like so:

    Author 1: <?php the_author_description(); *for author 1* ?>

    Author 2: <?php the_author_description(); *for author 2* ?>

    Author 3: <?php the_author_description(); *for author 3* ?>

    How can I write the php so that I can specify which the_author_description I want based on author ID? Unfortunately *for author 1* doesn't work ;).

    I already have the "running php in a page" problem sorted out. I'm successfully using runPHP to call my own bio (<?php the_author_description(); ?> works great automatically for the actual author of the page).

    Here's the author page in question: http://purplepapaya.net/etsy/editors/

    PS: I looked at http://codex.wordpress.org/Author_Templates, but I'm just not smart enough to go from there to where I need to be.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    There's no way to do it in the way you're looking to do it. That sort of behavior is not supported (though it is a good idea in the long run.. maybe I'll submit a patch for it).

    Anyway, this will do what you want:

    function get_user_description($ID) {
    $user = get_userdata($ID);
    return $user->description;
    }

    Stick that in your functions.php file for your theme. Then you can do this:
    <?php echo get_user_description(1); //for author 1 ?>

    And so forth.

  3. alsosara
    Member
    Posted 7 years ago #

    Thank you, Otto! I am trying to get this to work now. Does

    function get_user_description($ID) {
    $user = get_userdata($ID);
    return $user->description;
    }

    go into my theme's functions.php? That is what I'm trying now. I also put <?php get_user_description(3); ?> into the page.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Does function get_user_description($ID) go into my theme's functions.php?

    Yes. If you don't have one, create a new one. Make sure that the first and last lines are <?php and ?>, respectively.

    I also put <?php get_user_description(3); ?> into the page.

    Unlike the_author_description(), the function I wrote above does not output the text directly. So you will need to add an echo to that line, like I demonstrated above.

  5. alsosara
    Member
    Posted 7 years ago #

    Otto, thanks again! It was the echo that I needed. Sorry that I didn't catch that the first time. I'm really operating out of my league, but the great news is that it's all working now: http://purplepapaya.net/etsy/editors/

    Now I just have to get them to write their bios. Thank you so much, Otto42!

Topic Closed

This topic has been closed to new replies.

About this Topic