• Hi, how would I put the author name on the posts displayed on the front page of my web-site, say with ‘by Andrew Chapman’ etc (more than one author).

    I have a child theme with style.css only. Should I create a functions.php file and put the code in there?

    This bit of code crops up when I search re this issue:

    <?php the_author() ?>

    Is that what I should use?

    Thanks for your help,

    Andrew

Viewing 5 replies - 1 through 5 (of 5 total)
  • depending on if and where to you want the name of the author get linked, you could use:

    the_author() – no link at all; http://codex.wordpress.org/Function_Reference/the_author

    the_author_link() – link to the author’s website; http://codex.wordpress.org/Function_Reference/the_author_link

    the_author_posts_link() – link to the author’s posts’ archive; http://codex.wordpress.org/Function_Reference/the_author_posts_link

    there are related functions:
    Twenty Fourteen for example uses a combination of get_the_author() with the link added by get_author_posts_url() http://codex.wordpress.org/Function_Reference/get_author_posts_url

    – which seems the same what your theme uses for single posts.

    edit content.php (ideally in a child theme so that the edits don’t get lost when you upgrade the theme) and add for example the new code below this line:
    <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>

    new code:

    <div class="entry-meta">
    <?php printf( '<a class="author" rel="author" href="%s">%s</a>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), get_the_author() ); ?>
    </div>

    Thread Starter Andrew Chapman

    (@andrew-chapman)

    Thanks very much, alchymyth.

    I have found a file called content.php in the Expound theme which has the line you specify. Do I just put a copy of this in my child theme (which so far contains only style.css,) and then add the new code?

    Andrew

    Thread Starter Andrew Chapman

    (@andrew-chapman)

    I would just like to have ‘by Andrew Chapman’ etc, with no link. I can’t quite see where I put the ‘by’. I see the example at the first link you gave:

    <p>This post was written by <?php the_author(); ?></p>

    but I don’t know how this fits in with the code you gave.

    Thanks a lot,

    Andrew

    The code you posted is exactly what you need if all you want to do is display the author’s name. Your code would output:

    This post was written by Andrew Chapman.

    alchymyth’s code would output:

    This post was written by <a href="link-to-andrew-chapman-posts">Andrew Chapman</a>.

    Thread Starter Andrew Chapman

    (@andrew-chapman)

    Thanks a lot. Could you tell me you to add the author for the first post also – is it called the featured post?

    Andrew

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Author name on front page’ is closed to new replies.