WordPress.org

Ready to get started?Download WordPress

Forums

Current Author (67 posts)

  1. soupenvy
    Member
    Posted 9 years ago #

    Hey - I'm new to wordpress, naturally, and have searched high & low for a way to display a "current author" on an authors' archive page.

    I understand how to get an author name displayed within the loop, but cannot find anything for displaying an author name outside of the loop (author name at top of page). There's got to be a simple way that I'm merely overlooking.

    The closest I can come is by using the get-author-profile plugin: http://guff.szub.net/2005/01/31/get-author-profile/

    But it seems as though this should be doable without a plugin. Thanks.

  2. Kafkaesqui

    Posted 9 years ago #

    Could you define "current author"? Is this supposed to be the last author who's posted, or something else?

  3. soupenvy
    Member
    Posted 9 years ago #

    Sorry, I meant current author on an Author archive page.
    for Example, I want to say something as simple as:

    You're currently viewing "Steve stevensons" page of posts:

  4. Kafkaesqui

    Posted 9 years ago #

    With 1.5 you can create an author page template (author.php) and place it in the directory for your theme. An easy way to do this is duplicate the index.php for a theme and make whatever modifications you want. You can then include some PHP code to grab and display author details (outside The Loop):

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

    <h3>You're currently viewing <?php echo $curauth->user_firstname; ?> <?php echo $curauth->user_lastname; ?>'s page of posts:</h3>

    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;

  5. soupenvy
    Member
    Posted 9 years ago #

    Thanks man - worked great!

  6. dailyknight
    Member
    Posted 9 years ago #

    worked for me too (haha)...thanks

  7. maestro42
    Member
    Posted 9 years ago #

    i used this thanks, worked great!

  8. zeitgeist-y
    Member
    Posted 8 years ago #

    I can't get this solution to work?! This is how my author.php currently looks like:

    ---------------------------
    <?php get_header(); ?>

    <div id="content">

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

    <h3>You're currently viewing <?php echo $curauth->user_firstname; ?> <?php echo $curauth->user_lastname; ?>'s page of posts:</h3>

    </div>

    <?php get_sidebar(); ?>

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

    I can't even explain my problem. Have a look at the site:
    http://zeitgeist.collectanea.org

  9. Kafkaesqui

    Posted 8 years ago #

    zeitgeist-y: It's possible the queried vars are not getting set, so try this:

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

    Or the purely 1.5 way:

    <?php
    if(get_query_var('author_name')) :
    $curauth = get_userdatabylogin(get_query_var('author_name'));
    else :
    $curauth = get_userdata(get_query_var('author'));
    endif;
    ?>

  10. FionaDixit
    Member
    Posted 8 years ago #

    As a matter of interest - can this be done for version 1.22?

    Thanks

  11. Kafkaesqui

    Posted 8 years ago #

    The code blocks above other than the last one marked "purely 1.5" should work in 1.2.x, though you can't create an author.php template to run it off (or rather you can, but WordPress won't acknowledge it).

  12. FionaDixit
    Member
    Posted 8 years ago #

    Thanls Kafkaesqui,

    Where do I actually place that code?

    Thanks
    F

  13. Kafkaesqui

    Posted 8 years ago #

    Where ever you want it displayed.

    You can wrap the whole thing (script and anything it's suppose to display) in an if statement that tests whether author_name or author have been passed as a query. This way it's not displayed on other page types:

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

    <h3>You're currently viewing <?php echo $curauth->user_firstname; ?> <?php echo $curauth->user_lastname; ?>'s page of posts:</h3>

    <?php endif; ?>

  14. FionaDixit
    Member
    Posted 8 years ago #

    Thanks for that but it didn't show up any authors when I clicked on an author ling from '<?php wp_list_authors('optioncount=1&show_fullname=1&hide_empty=1'); ?>'

    Not sure why though :)

  15. thepete
    Member
    Posted 8 years ago #

    Huh, here's an odd question--when I use the tag in Fiona's post directly above, I get all of the authors who have posted on my site except for one--me. The admin doesn't show up. Is there a way to change this?

    Sorry, I tried searching the codex, but I find it rather confusing. I mean, what's the difference between the 'go' and the 'search' buttons, anyway?

  16. Kafkaesqui

    Posted 8 years ago #

    @thepete

    See the info on the 'exclude_admin' parameter for wp_list_authors():

    http://codex.wordpress.org/Template_Tags/wp_list_authors

  17. nearlythere
    Member
    Posted 8 years ago #

    FYI: in case anyone is using this thread to build Author Templates, or include author information on Archive Templates- there's aa new codex page on this topic. Much of the information comes from this thread, and Kafkaesqui's helpful advice. Thank you.

    http://codex.wordpress.org/Author_Templates

    Any edits and contributions welcome to speed up the process of getting this document beyond 'draft' stage!

  18. kalico
    Member
    Posted 8 years ago #

    Hi Kafkaesquí. You are an amazing help with this. I am close to having what I want, but not quite.

    What I'm trying to achieve is this: On each post, after the title, I list the author's name (POSTTITLE, by so-and-so). I want to have the author's name link to a page that shows all the profile information for that particular author.

    Is this possible? I have your get_author_profile plugin activated, and have also tried the code in this thread, but neither one is getting me exactly where I want to go.

    Thanks, Marci :)

  19. kalico
    Member
    Posted 8 years ago #

    For the record, my author.php page does show only the profile. However, it is now the default page when I use 'the_author_posts_link'. I would like to call it using something different, so that 'the_author_posts_link' continues to work as it's supposed to.

    Marci :)

  20. kalico
    Member
    Posted 8 years ago #

    I solved this problem in part by using ONLY the index.php file, and removing the author.php file. (It seems the_author_posts_link looks for the author.php file first as a template.) I used the IF statement supplied above, and that way the index.php shows the author profile information ONLY if the author is specified (as in the_author_posts_link) but not otherwise.

    I also modified the text in the IF statement, so that it reads well...something like this:

    You're viewing Jane Smith's page of posts.

    Jane Smith is a very nice person who likes dogs. <<-- this is the profile information, supplied by the code in the if statement above.

    Post #1
    Summary

    Post#2
    Summary

    Post #3

    ETC ETC

    Hope that helps someone. If anyone has a cleaner way, great. I'm new to WP and learning :)

    Marci :)

  21. Kathy_P
    Member
    Posted 8 years ago #

    kalico, I'm trying to figure out how what you accomplished with the index.php differs from the results you got with author.php? The author template can display both the profile and the posts, which is what it sounds like you did with your index.php. Or did I miss something?

  22. Kathy_P
    Member
    Posted 8 years ago #

    I developed my author.php from index.php as well. I found that when used in the author template, any author template tag used after The Loop (that is, after the <?php endwhile; endif; ?>) worked properly, despite assertions in the Codex that they must be used within The Loop. I used them in my sidebar div before getting the sidebar template. I am specifically referring to the template tags for displaying the author description, author name, and author email. I presume the others would work. The only thing I needed the code in "the purely 1.5 way" above was to get the author's name in the title as mentioned above, because that comes before The Loop.

  23. Kathy_P
    Member
    Posted 8 years ago #

    I would like to get all the posts on the author.php page to be displayed oldest first, so that they could be read in the order they were written, instead of newest first as they are on the blog. I have done some searching on this forum, but am not sure how to adapt it to the author template. Also, the link to this thread wordpress.org/support/topic.php?id=26613 gave me an internal server error, so I couldn't read it.

  24. Kafkaesqui

    Posted 8 years ago #

    Kathy_P

    Fixed link: http://wordpress.org/support/topic/26613

    You can do this by initializing The Loop with query_posts() and the 'order' parameter:

    <?php query_posts("order=ASC"); ?>

    If you're using previous/next post pagination, then make sure to account for it this way:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("order=ASC&paged=$paged");
    ?>

    Note the reason the Codex pages specify using certain tags in The Loop is because they receive their info from post data, which is often only available in a post loop. However if used after The Loop has run, they *can* work off data originating from the last post on the page; it's just that their behavior will not be consistent across all possible uses outside of The Loop.

    Helpful links:
    http://codex.wordpress.org/template_tags/query_posts
    http://codex.wordpress.org/The_Loop

  25. Kafkaesqui

    Posted 8 years ago #

    Uh, let's nix the code for query_posts above, and go with this instead:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if(get_query_var('author')) {
    $author = get_query_var('author');
    $auth_q = 'author';
    } else {
    $author = get_query_var('author_name');
    $auth_q = 'author_name';
    }
    query_posts("$auth_q=$author&order=ASC&paged=$paged");
    ?>

    Forgot to take care of the author in the query...The above provides the author query to query_posts based on the query that's occured--either by author ID, or author name.

  26. Kathy_P
    Member
    Posted 8 years ago #

    Thank you, Kafkaesqui. I had experimented with query_posts, but couldn't get it to work quite right. I am looking forward to the day when this function is documented more thoroughly in the Codex.
    Just to confirm my understanding--the above code should go right before The Loop, right? Also, using the_excerpt instead of the_post shouldn't require a change in the code you provided, should it?

  27. Kafkaesqui

    Posted 8 years ago #

    "Just to confirm my understanding--the above code should go right before The Loop, right? "

    That's correct. Think of it as a prefix to The Loop itself.

    "Also, using the_excerpt instead of the_post shouldn't require a change in the code you provided, should it?"

    You're replacing the_post() with the_excerpt()? Don't understand why you would (or want to). If you mean you're using the_excerpt() in place of the_content(), there's no difference in how you would use the query_posts() code above.

  28. Kathy_P
    Member
    Posted 8 years ago #

    You are correct: I am replacing the_content() with the_excerpt. I "mistyped." Okay, I think I've got my author template doing everything I want it to. But I want to be able to access specific authors via the wp_list_pages() on the sidebar. It is probably easier to show you than to explain it. Look at the sidebar on my site. Under "Menu" you will see a page called "Essays." I plan on having each author's page listed as a child of "Essays," and then all the essays by that author as children-Pages of the author Page. Right now I only have one author (Rundy) and one essay written by him listed below his name. Currently the template for the "Rundy" page is very similar to my author.php, except I use query_posts( ) to specify the author. But could I make a much simpler template that just called the author template? I know that http://www.coldclimategardening.com/author/rundy/ is one way to write the query that will bring up the author.php, but how do I include it on a template for the Page "Rundy" so that it will automatically take the reader there?

  29. Kafkaesqui

    Posted 8 years ago #

    I think we need further clarification on what you're up to here.

    I see Essays, and Rundy's 'child' Page. So at this point, you want to display each author's info (user profile?), and an excerpt of their posts beneath that. Correct?

    Hmm. You'll probably run into problems, specifically with pagination (next/previous posts), since that's tuned to work in query type page displays (such as archives, categories and authors). But ignoring that for now (...), you might incorporate your author.php template into a custom Page template, and assign that to each author Page.

  30. Kathy_P
    Member
    Posted 8 years ago #

    I feel like I am not completely understanding something you've already said, or not fully incorporating it into the last piece of the puzzle. It sounds like what you are suggesting is to copy all the code from author.php into a custom template. That's pretty much what I've already done, except I specified the author by "cheating." I had Rundy create the Page himself while logged in, so he is the author by default. But not all my contributors are as comfortable using WordPress. As a custom template, it would not be called in response to a query, so how would I assign the author? It seems like I would use a modification of the code up above in "the purely 1.5 way," but I'm not quite sure what to modify. And if I did it that way, I would have to make a custom template for each author, changing one line (one number, actually, the user_id) in each. Is that what you are saying?

    Is there a way to "get" the author template in the same way you "get" the sidebar template? In other words, if I create a custom template, can I put something like '<?php get_author(2)?>` (where the author's id is 2) and it will use the author template for author 2 instead of page.php (or index.php)? I'd still have to make a custom template for each author, though. Or would I? I can't think how I would assign it dynamically.

Topic Closed

This topic has been closed to new replies.

About this Topic