php if语句没有正确评估

时间:2012-02-22 06:14:51

标签: php wordpress if-statement

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

这可能是一个简单的解决方案,但正如我已经说过的,我是一个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也会出现,但是列表中没有任何内容出现(我猜是因为只有一个帖子而且你已经在查看它了。)

任何帮助都会受到赞赏,已经很晚了,我的大脑已经融化了。如果有任何需要澄清的话,请告诉我。

提前致谢。

1 个答案:

答案 0 :(得分:1)

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