php-if语句评估不正确


php if statement not evaluating properly

这是我第一次在这里发布问题,以前这是一个宝贵的资源,所以我想也许有人能回答我的问题。

这可能是一个简单的解决方案,但正如我已经说过的,我是一个PHP傻瓜。原谅我。

这是我的代码:

    <?php wp_reset_postdata(); // reset the query ?>
<?php $authorposts = get_the_author_posts();
    if ($authorposts < 1) {
    echo " ";
    }
    else { ?>
<div class="single-sidebar"><!--expert_blog start-->
    <div class="single-sidebar-middle">
    <div class="single-sidebar-top">
    <h3>More Posts by <?php the_author();?></h3>
    </div>
    <p><?php echo get_related_author_posts(); ?></p>
    <div class="single-sidebar-bottom">
        <div class="more_blog"><a href="<?php echo get_author_posts_url(get_the_author_meta( 'ID' )); ?>">+ Read more</a></div>
    </div>
    </div>
</div>
<div class="clear"></div>
<?php wp_reset_postdata(); // reset the query ?>

这应该做的是:获取特定作者(当前正在查看的帖子)的帖子数量,并将其输出到一个条件语句中,如果它是1或小于1,则不显示任何内容。否则,显示每个帖子的标题。

发生了什么:即使只有一篇文章提交给作者,div也会出现,但列表中什么都没有出现(我猜是因为只有一篇帖子,而你已经在查看了)。

任何帮助都将不胜感激,现在已经很晚了,我的大脑已经融化了。如果有什么需要澄清的,请告诉我。

提前谢谢。

应该是if ($authorposts <= 1) 而不是if ($authorposts < 1)