• Hi all, I’m new to wp theme designing.

    Say I’m writing single.php. How can I do

    <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <div id=”<?php
    if(author_of_the_post == “admin”)
    echo ‘single1’;
    else
    echo ‘single2’;
    ?>”>

    I.e., what should be “author_of_the_post”?

Viewing 5 replies - 1 through 5 (of 5 total)
  • are just trying to get the name of the author who posted the post, to show up on the posts its <?php the_author(); ?>

    Thread Starter darksair

    (@darksair)

    Yes. the_author() displays the name of the author on the page. However what I need is a PHP string, so that it can do a comparison with a string constant.

    okay tell me exactly what you want to do…
    https://codex.www.ads-software.com/Template_Tags/the_author
    maybe this could help…

    Thread Starter darksair

    (@darksair)

    I need a function that returns the author as a string, so that I can do

    if (func() == “admin”)
    blabla…

    the_author() seems to fail to be this func(), because, if I understand it right, the_author() just display the author’s name in html.

    Darksair, I think you’re trying to get the author’s name without being displayed on the page, am I right?

    If so you can use $authordata = get_userdata($post->post_author); to get the user’s data and echo $authordata->user_nicename;

    Instead of using user_nicename you can use any other variable you find in the get_userdata codex page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to retrieve the author of the post’ is closed to new replies.