• Resolved TheMarque

    (@themarque)


    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>’

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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
    }
    Thread Starter TheMarque

    (@themarque)

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

    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
    }?>
    Thread Starter TheMarque

    (@themarque)

    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
    }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excluding author box for certain authors on posts’ is closed to new replies.