WordPress.org

Ready to get started?Download WordPress

Forums

How to show who writes a post (17 posts)

  1. deb0
    Member
    Posted 8 years ago #

    How do you make it so the viewer can see who submited the post.

  2. Kafkaesqui

    Posted 8 years ago #

  3. efinkartlu
    Member
    Posted 8 years ago #

    I'm little helpless with php and everything, so can you help me?

    I want to put that 'who submited the post' thing on my blogs too. In which file and where there i should put that 'Posted by <?php the_author_nickname(); ?>' ?

  4. Cypher
    Member
    Posted 8 years ago #

    This would go in your index.php file for your theme within "the loop".

    To get an idea of how that'd work, look at /wp-content/themes/default/index.php and look at line #11. You will see the call to the_author() there and notice that it's been commented out.

    Regards

  5. efinkartlu
    Member
    Posted 8 years ago #

    Thanks for that.

    One more question :P

    How can you put a tag around the_author that it mails to that author, who has written concerned blog?

    Like if i wrote then there will be my nick and link 'mailto:'. And if my pal wrote there, then that mail link replaced by my pals mail.

  6. efinkartlu
    Member
    Posted 8 years ago #

    Not needing help anymore, i found the answer from that page where was that the_author thing too :P

  7. deb0
    Member
    Posted 8 years ago #

    thank you for the fast help!!!!!!!!!!!!!!!!!!

  8. Tfleming
    Member
    Posted 8 years ago #

    I have a similar question:

    My blog (UNSG.org) will soon be accepting contributions from guest authors. I would like to indicate the author of these posts, but I don't want authorship to show up when I, the admin, is the author (which is most of the time).

    Any suggestions for limiting the author php code, so that it only works with "editor" or "author" user roles, and not for "admin" role?

    Thanks!

  9. Kafkaesqui

    Posted 8 years ago #

    Tfleming, a simple way to do this would be:

    <?php if('admin' != get_the_author_login()) the_author(); ?>

  10. Tfleming
    Member
    Posted 8 years ago #

    Thanks, Kafkaesqui

    That seems to work, but I need a small adjustment. I replaced to commented-out basic " by <?php the_author(); ?> "

    I need to move the "by" inside the

    "by <?php if('admin' != get_the_author_login()) the_author(); ?>"

    so that it doesn't show up when the authorship isn't displayed.

    Very new to php coding, obviously, but I tried to move it various places by looking at other code elements. Thought it might just be easiest to ask you, where do I put this?

    Thanks for your help!!

    Tony

  11. Kafkaesqui

    Posted 8 years ago #

    <?php if('admin' != get_the_author_login()) echo 'by ' . get_the_author(); ?>

  12. Tfleming
    Member
    Posted 8 years ago #

    Wow... that seemed to work! But it introduced a new problem. I need to now insert a break if it displays the author other than admin, but not if the author is admin. Where inside that php code would I put this?

    While I'm asking, is it possible to also include in that code a call to the author's image (again, when other than admin) so that it displays next to each entry they post?

  13. Kafkaesqui

    Posted 8 years ago #

    "I need to now insert a break if it displays the author other than admin, but not if the author is admin."

    That's a bit vague. Where does the break go?

    "is it possible to also include in that code a call to the author's image"

    Certainly, but I've no idea what you're using (if anything) to display author images.

  14. Tfleming
    Member
    Posted 8 years ago #

    Sorry, more or less a newbie.... I'll try to clarify. Here's the code as it stands:

    <h2>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    <small> <?php if('admin' != get_the_author_login()) echo 'by ' . get_the_author(); ?>
    <?php the_time('F jS, Y') ?>

    This prints the title (as a permalink), then on the next line the author's name (unless the admin) and the date.
    I need to put a break between the author's name and the date, but only if not an admin.

    If I just a <br> before the date code now, I get an empty line between the title and date if the author is the admin. So, I presume I need to insert the <br> somewhere in the code you provided earlier so that it only shows up when the admin is not the author.

    On the images question, is there a way to create a code that calls the image up (sorry if not using the right terminology) the same way that <?php get_the_author(); ?> calls up the author's name?
    Something like <?php get_the_author_photo(); ?>
    which...I suppose... would have to be stored somewhere in their WordPress profile? Maybe put the src= in their biographical information box?

    Thanks!

  15. Kafkaesqui

    Posted 8 years ago #

    RE: Inserting a break only when author is displayed...

    <?php if('admin' != get_the_author_login()) echo 'by ' . get_the_author() . '<br />'; ?>

    Here's a less unwieldy version:

    <?php if('admin' != get_the_author_login()) : ?>
    by <?php the_author(); ?><br />
    <?php endif; ?>

    RE: Author image...

    There are a number of ways to accomplish this, but probably the simplest is to upload images for your authors based on some component of their profile, such as ID or login, and use that for the dynamic part to your image *code*. Here's an <img> tag example using user/author ID (ID.jpg) as the image filename:

    <img src="/images/authors/<?php the_author_ID(); ?>.jpg" alt="<?php the_author(); ?>" />

    A somewhat more complete author image solution would be found in a plugin like:

    http://www.coffee2code.com/archives/2005/03/28/plugin-author-images/

  16. coreyallen
    Member
    Posted 8 years ago #

    Hello.
    I'm having the hardest time using this, or the author images plugin.
    No matter what i use, all i get is the ouput of the author name..but no image.
    Please help!!!!!!!

    Example:
    I inserted this
    <img src="/images/authors/<?php the_author_ID(); ?>.jpg" alt="<?php the_author(); ?>" />
    into my index, and i have the images in the /images/authors/ folder...no luck

  17. Chris Burgess
    Member
    Posted 7 years ago #

    corey,

    in wordpress there is a distinction between the_FOO() tags and get_the_FOO() tags.

    the_author() will OUTPUT the result, while get_the_author will RETURN the result.

    <?
    $x = the_author() ;
    // prints author name, and sets $x to "true"

    $y = get_the_author() ;
    // prints nothing, and sets $y to the author name
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags