我试图在页面上列出作者,但排除了管理员(我自己)。我正在使用松鼠的儿童主题,这是我迄今为止的代码:
<?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; ?>
我尝试使用这次讨论中的解决方案,但我认为我做得不对,因为当我添加这行代码时:
if(get_the_author_meta('display_name', $author->post_author) != 'admin'):
下:
foreach ($authors as $author):
它只是破坏了整个网站(屏幕是白色的)。这对我来说都是新的,所以有人能帮我弄清楚我做错了什么吗?
非常感谢!
您遇到的白色屏幕是一个致命的PHP错误。出于安全原因,您没有看到错误是什么。
但是,在开发过程中,您需要关闭此功能。只需编辑wp-config.php
并将WP_DEBUG
设置为true
即可。
至于你的问题,你可能想要这样的东西:
if($author->post_author == 1) continue;
作为CCD_ 4内部的第一行。id 1应该是您的userid,因为在WP中创建的第一个用户有1,关键字continue
跳到foreach的末尾,从而跳过您的用户。
如果您更喜欢使用用户名,请使用以下内容:
if(get_the_author_meta('user_login', $author->post_author) == 'admin') continue;