Support » Plugins » Variable for author name?

  • Resolved ghugh083

    (@ghugh083)


    Hi! I’m setting up a web outlet for a student paper. Thing is: I want the author’s name for each article to appear with the date, however all posts are made from the same WordPress account. Short of writing the name in the post manually with some sort of CSS formatting, which is not at all what I want to do, could a variable (“personalized field”) be used to accomplish this? How could it be accessed from the template in The Loop?

    Or, is there a plugin that could do this nicely?

    Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ghugh083

    (@ghugh083)

    I looked around and me suis démerdé.

    Eureka! So the key is that you want to use WordPress’ highly underrated and underused “Custom Fields”.

    When you create a post in the WP Dashboard, underneath the editor there’s a section for Custom Fields. You want to add a new key called “Author” (sans quotes) and the value will be whatever the name of the author is.

    Now within your theme (in your single.php or index.php, just below ‘the_title’ you want to add the following:

    <span>
    <?php
    $author2 = get_the_author();
    $values2 = get_post_custom_values("Author");
    if (empty ($values2)) {
    echo "By " . $author2;
    } else {
    echo "By " . $values2[0];
    }
    ?></span>

    What the above code does is display the author’s name from the Custom Field that you input. If there is nothing in there, then it will just use the actual WP admin’s name of who posted the article.

    Hope that helps!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Variable for author name?’ is closed to new replies.