I am trying to list authors on a page, but exclude the admin (myself). I am using a child theme of squirrel and this is my code so far:
<?php
$authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts);
if($authors):
foreach($authors as $author):
?>
<div class='author' id='author-<?php the_author_meta('user_login', $author->post_author); ?>'>
<h3><a href="<?php bloginfo('url'); ?>/author/<?php the_author_meta('user_login', $author->post_author); ?>"><?php the_author_meta('display_name', $author->post_author); ?></a></h3>
<?php if(get_the_author_meta('description', $author->post_author)): ?>
<div class='description'>
<?php echo get_avatar(get_the_author_meta('user_email', $author->post_author), 80); ?>
<p><?php the_author_meta('description', $author->post_author); ?></p>
</div>
<?php endif; ?>
<?php
$recentPost = new WP_Query('author='.$author->post_author.'&showposts=1');
while($recentPost->have_posts()): $recentPost->the_post();
?>
<h4>Recent Article: <a href='<?php the_title();?>'><?php the_title(); ?></a></h4>
<?php endwhile; ?>
</div>
<?php endforeach; endif; ?>
I tried using the solution from this discussion, but I don’t think I am doing it right because when I add this line of code:
if(get_the_author_meta('display_name', $author->post_author) != 'admin'):
under:
foreach ($authors as $author):
it just breaks the entire site (the screen is white). This is all new to me, so can someone please help me figure out what I am doing wrong?
Thanks a lot!
The white screen you are experiencing is a fatal PHP error. You are not seeing what the error is, for security reasons.
However, during development, you want this feature off. Just edit
wp-config.php
and setWP_DEBUG
totrue
.As for your question, you might want something like:
…as the first line inside the
foreach
. The id 1 should be your userid because the first user created in WP has 1, and the keywordcontinue
jumps to the end of the foreach, thus skipping your user.If you prefer doing this by username, use this: