WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Profile pic on pages not posts (5 posts)

  1. giveabrick
    Member
    Posted 5 years ago #

    Hi,
    I need some help adjusting the code so that a profile pic shows up in posts but not on pages. Right now I have <?php echo get_avatar( get_the_author_email(), '50' ); ?> in the loop but that has resulted in authors images being on both post and pages.

    Is there somewhere else I should put this so that only posts get pics? Or is there something else I should do in a different place to override this instruction on pages?

    Many thanks for your help,
    Eleanor

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Try:

    <?php if(is_page()) echo get_avatar( get_the_author_email(), '50' ); ?>

  3. giveabrick
    Member
    Posted 5 years ago #

    Hi Esmi,
    Thanks for your help but that shows pic on page and not posts whereas I'd like it the other way round (pic showing on posts, not pages)

    I tried changing what you gave me to:

    <?php if(is_post()) echo get_avatar( get_the_author_email(), '50' ); ?>

    and then ..
    <?php if(is_not_page()) echo get_avatar( get_the_author_email(), '50' ); ?>

    followed by ..
    <?php if(is_post()) echo get_avatar( get_the_author_email(), '50' ); ?>

    and ...
    <?php if(have_post()) echo get_avatar( get_the_author_email(), '50' ); ?>

    but all gave errors saying:
    Fatal error: Call to undefined function is_post() in /home/custard/public_html/giveabrick/wp-content/themes/atahualpa/index.php on line 14

    So next question I guess is what function do I need instead of 'is_page to get the pic showing on posts not pages?

    Many thanks for your help and patience,
    Eleanor

  4. esmi
    Forum Moderator
    Posted 5 years ago #

  5. giveabrick
    Member
    Posted 5 years ago #

    Hi,
    I wasn't sure where to put that (sorry, I'm brand new to this) but your link to the conditional tags page was brilliant because I've found this to work:

    <?php if(is_home()) echo get_avatar( get_the_author_email(), '50' ); ?>
    <?php if(is_single()) echo get_avatar( get_the_author_email(), '50' ); ?>

    Without that page you showed me, I would never have known what to put for a post and using the (is_home) allows author pics to show on main page as well as single post pages.

    Someone cleverer than me will have a neater way to do this but I'm just delighted because it's doing what I want it to so thank you ever so much for helping me.
    Eleanor

Topic Closed

This topic has been closed to new replies.

About this Topic