WordPress.org

Ready to get started?Download WordPress

Forums

Notating Guest Bloggers (10 posts)

  1. andymatic
    Member
    Posted 9 years ago #

    I know that the_author() coughs back the name of the author - but what is the underlying variable?

    I want to be able to note when a post is from a guest blogger so I was trying.


    <?php the_author() ?>
    <?php if (some_variable != my_name_or_id) { echo ", Guest Blogger";} ?>

    Wasn't sure what my choices were for the author variable of a certain post as well as my own variable as an author.

  2. NuclearMoose
    Member
    Posted 9 years ago #

  3. andymatic
    Member
    Posted 9 years ago #

    I had tried


    <?php the_author() ?>
    <?php if (the_author() != "My Name") { echo ", Guest Blogger";) ?>

    And instead of using the_author() as a variable in the comparison - it outputs the_author() - showing it twice.

  4. zerolives
    Member
    Posted 9 years ago #

    What causes this problem is the fact that the_author() actually outputs text instead of returning a variable for usage. Try something like this:

    $variable = the_author();

    and then use $variable for the comparison. It probably won't work. But at least you tried!

  5. andymatic
    Member
    Posted 9 years ago #

    Same result:


    Posted by <?php the_author(); ?>


    <?php
    $author_name = the_author();
    if ($author_name != "My Name") echo ", Guest Blogger";
    ?>

    Still produced My Name My Name for me and then Author Name Author Name, Guest Blogger for the non-me bloggers.

    Any other ideas?

  6. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    The problem is that all of the author template functions echo. The solution: output buffering.

    <?php
    ob_start();
    the_author();
    $my_author = ob_get_contents();
    ob_end_flush();
    if ($my_author!='My Name') { echo ', Guest Blogger'; }
    ?>

    This will output the_author once and then append ', Guest Blogger' if the author is not 'My Name'.

  7. andymatic
    Member
    Posted 9 years ago #

    Alright - now I get to learn about output buffering - thank you for the link and help... gonna go try out the code now - be back in a few minutes to report back.

  8. andymatic
    Member
    Posted 9 years ago #

    Holy crap it worked! Thanks!

    Added to wiki:

    http://wiki.wordpress.org/?pagename=NotateGuestBloggers

  9. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    I don't believe it. I've been Kafkaesqui'd.

    An easier solution:

    Figure out what your author ID is. Say it's 2.

    <?php
    the_author();
    if ($post->post_author != 2) { echo ', Guest Blogger'; }
    ?>

    Output buffering is neat, but a bit overkill here.

  10. andymatic
    Member
    Posted 9 years ago #

    Thanks - I'll fix the wiki entry.

    (20 seconds later)

    Oh, you already did! Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.