WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Excluding author box for certain authors on posts (5 posts)

  1. TheMarque
    Member
    Posted 2 years ago #

    Hello all!

    I built my own author-box (a biography, avatar, and social media links) to be displayed above every post on the single.php template. However, I only want it to be displayed above authors who work for the site, and not from authors we reblog or are temps. So I want to exclude the author box from showing up on the page for ID #3 or "externalsource".

    Could you guys help me out real quick? Thanks!

    Here is my code:
    `<div id="authorbox">
        <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_email(), '80' ); }?>
    <div class="authortext">
    <h4>About <?php the_author_posts_link(); ?></h4>
           <p><?php the_author_description(); ?></p>
    </div>
    </div>'

  2. imikedesigns
    Member
    Posted 2 years ago #

    Try this and let me know if it works. The syntax might be off. This would require you to add the id of each author that works for the site.

    $getid = $posts[0]->post_author;
    if($getid == 3){
    // Do something that is specific for user with ID 3
    
    <div id="authorbox">
        <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_email(), '80' ); }?>
    <div class="authortext">
    <h4>About <?php the_author_posts_link(); ?></h4>
           <p><?php the_author_description(); ?></p>
    </div>
    </div>
    
    }
    else{
    // Do Nothing
    }
  3. TheMarque
    Member
    Posted 2 years ago #

    Thanks for responding!
    Yes, when I try that code it has a syntax error
    Parse error: syntax error, unexpected '<'

  4. imikedesigns
    Member
    Posted 2 years ago #

    You may have to open and close php in spots to get it to work. Anyway, I think $getid = $posts[0]->post_author; is the direction you need to go. Sorry i suck at PHP still. See if this changes anything.

    <?php $getid = $posts[0]->post_author;
    if($getid == 3){?>
    // Do something that is specific for user with ID 3
    
    <div id="authorbox">
        <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_email(), '80' ); }?>
    <div class="authortext">
    <h4>About <?php the_author_posts_link(); ?></h4>
           <p><?php the_author_description(); ?></p>
    </div>
    </div>
    
    <?php}
    else{
    // Do Nothing
    }?>
  5. TheMarque
    Member
    Posted 2 years ago #

    Hey, perfect, I was actually just now trying closing of the tags and also using echo 'authorbox code';. However, I had put the closing } before the second <?php

    And, this code works! I just had to put a space between <?php and } but it works.
    And actually, it blocks out the code on every page except UserID 3. So I just reversed it and it works so well. Thanks for your help!

    FYI, here is what I ended up doing:

    <?php $getid = $posts[0]->post_author;
    if($getid == 3){
    // Do Nothing
    
    }
    else{
    ?>
    // Do something that is specific for user with ID 3
    <div id="authorbox">
        <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_email(), '80' ); }?>
    <div class="authortext">
    <h4>About <?php the_author_posts_link(); ?></h4>
           <p><?php the_author_description(); ?></p>
    </div>
    </div>
    <?php
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic