Forums

including author name in certain posts while hiding in others (9 posts)

  1. bage1
    Member
    Posted 2 years ago #

    I currently have the author name showing under a post title as defined in single.php:

    By <?php the_author(); ?>

    however, I would like the exclude the author name from certain posts while still showing it in others. is there a way to do this? I was thinking through custom fields, but not sure how.

    alternatively, is it possible to exclude a certain author's name from showing up? ie, if "admin" writes a post, then the author name would not show under the post title, but if someone else is the author, it shows up regularly?

  2. bage1
    Member
    Posted 2 years ago #

    bump

    any thoughts on how to exclude a certain author name from showing up while others will show regularly?

  3. bage1
    Member
    Posted 2 years ago #

    upp

  4. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    It's not as easy as it should be. There's a distinct lack of (non-deprecated) author functions to play with. How about:

    <?php if( the_author_meta( 'nickname' ) != 'admin' ) :?>
    By <?php the_author(); ?>
    <?php endif;?>

    If you had a list of authors, you could possibly set up an array of authors you didn't want to show.

    <?php
    $hide_authors = array( 'admin', 'joe', 'fred' );
    if( !in_array(the_author_meta( 'nickname' ), $hide_authors)) :?>
    By <?php the_author(); ?>
    <?php endif;?>

    But all of the above are just untested ideas...

  5. bage1
    Member
    Posted 2 years ago #

    thanks for the ideas, but neither one seems to work at least set up like that, it seems to show the author name even if its admin.

    unfortunately I don't have enough knowledge over php to know whats wrong with it, any ideas?

  6. bage1
    Member
    Posted 2 years ago #

    bump, any other ideas?

  7. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    Try user_login instead of nickname. I think it's just a matter of getting the right combination of parameter and comparison string. Obviously, if the site's admin has another login username, you'd need to amend it to suit.

    http://codex.wordpress.org/Template_Tags/the_author_meta

    lists all of the possibilities.

  8. bage1
    Member
    Posted 2 years ago #

    hmm

    I think there might be something else wrong, both of the suggestions seem to show up as "adminBy admin"

  9. Edward Caissie
    Member
    Posted 2 years ago #

    Here is a snippet to work with:

    <?php if ((get_userdata(intval($author))->ID) != '1') ?>
    By <?php the_author(); ?>
    <?php endif; ?>

    Hopefully it will be of some help ...

Topic Closed

This topic has been closed to new replies.

About this Topic