0

I'm getting very confused trying to get an existing bit of code to work within a conditional if/else bit of code. I can't get the syntax correct. All the echo commas and semi colons (sorry I'm not a coder).

Existing code to show a post author info under the post content:

    <div id="author-bio">
     <h3>About The Author</h3>
     <?php echo get_avatar( get_the_author_id() , 80 ); ?>
     <h4><?php the_author_posts_link(); ?></h4>
     <div class="desc"><?php the_author_meta('description'); ?> </div>                       
   </div><!--end author-bio-->

And the new code that I want to use to prevent the author info for a post created by the main admin account to show:

<?php global $wp_query; 
$thepostid = $wp_query->post->ID;
$postdata = get_post($thePostid, ARRAY_A);
$authorid = $postdata['post_author'];
if ($authorid==1)
{
echo 'Show nothing';
}
else
{
echo 'Existing author info code to go here';
}
?>

Both bits of code work separately but combining them as I've noted above results in mark up errors in Dreamweaver and the site breaking in browser. Can someone please give me a few pointers on how to edit the first bit of code to fit in the else part?

0

you code may look like this

    <?php global $wp_query; 
    $thepostid = $wp_query->post->ID;
    $postdata = get_post($thePostid, ARRAY_A);
    $authorid = $postdata['post_author'];
    if ($authorid==1)
    {
    echo 'Show nothing';
    }
    else
    {
    ?>
    <div id="author-bio">
    <h3>About The Author</h3>
    <?php echo get_avatar( get_the_author_id() , 80 ); ?>
    <h4><?php the_author_posts_link(); ?></h4>
    <div class="desc"><?php the_author_meta('description'); ?> </div>
    </div>
    <?php
    }
    ?>
  • Hi Ravs, Thanks, that sorted it out. I think I was over complicating things by using apostrophes. – Nicko Jun 6 '13 at 8:57
0

Here's a slightly simpler approach. If the author is 1, show the block. Otherwise, it'll skip right over it.

<?php if ( 1 != get_the_author_meta( 'ID' ) ) : ?>

    <div id="author-bio">
        <h3>About The Author</h3>
        <?php echo get_avatar( get_the_author_meta( 'ID' ), 80 ); ?>
        <h4><?php the_author_posts_link(); ?></h4>
        <div class="desc"><?php the_author_meta( 'description' ); ?> </div>                       
    </div><!--end author-bio-->

<?php endif; ?>
  • Thanks Matthew, I'll try this out in the future if I need that solution. I'm not sure if that would work the right way round for what I was trying to accomplish. My client wanted to be able to have a post not published by a specific member of staff. Usually each post is attributed to a user who is a staff member with an author page. Sometimes they need posts to be not associated with a staff member. Hence making it so that it won't show anything if posted by me, the main admin. Cheers. – Nicko Jun 6 '13 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.