首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编写此php条件语句的正确方式

编写此php条件语句的正确方式
EN

Stack Overflow用户
提问于 2016-07-01 19:10:37
回答 4查看 135关注 0票数 0

我不太精通php,因为我是个新手。我正在尝试使用这些代码行,但是遇到了错误。正确的写法是什么:

代码语言:javascript
复制
<?php 
if ( function_exists( 'wpsabox_author_box' ) ) {
    echo wpsabox_author_box();
} else {
    echo (
            '<div class="postauthor">
                <div class="authorprofilepix">'
                     get_avatar( get_the_author_id() , 80 );
                '</div>

                <div class="authorprofile">
                    <h4>' the_author(); '</h4>
                    <p>' the_author_description(); '</p>
                </div>
                <div class="clearfix"></div>

            </div><!--end postauthor-->');

}
?>

在期待中感谢!

EN

回答 4

Stack Overflow用户

发布于 2016-07-01 19:15:30

您应该在echo调用内的字符串和函数调用之间添加点。

例如:

代码语言:javascript
复制
echo ('string' . function() . ' string ');
票数 3
EN

Stack Overflow用户

发布于 2016-07-01 19:20:24

使用以下方法:

代码语言:javascript
复制
<?php if (function_exists( 'wpsabox_author_box' ) ) {
            echo wpsabox_author_box();
        } else { ?>
         <div class="postauthor">
            <div class="authorprofilepix">'
             <?php echo get_avatar( get_the_author_id() , 80 ); ?>
            </div>
            <div class="authorprofile">
                <h4><?php echo  the_author(); ?></h4>
                <p><?php echo the_author_description(); ?></p>
            </div>
            <div class="clearfix"></div>

        </div><!--end postauthor-->

   <?php     }

 ?>
票数 1
EN

Stack Overflow用户

发布于 2016-07-01 20:08:30

下面是你的代码应该是什么样子才能工作:

代码语言:javascript
复制
<?php 
if ( function_exists( 'wpsabox_author_box' ) ) {
    echo wpsabox_author_box();
} else {
    echo '<div class="postauthor">
            <div class="authorprofilepix">' . get_avatar(get_the_author_id(), 80 ); . '</div>
                <div class="authorprofile">
                    <h4>' . the_author() . '</h4>
                    <p>' . the_author_description() . '</p>
                </div>
                <div class="clearfix"></div>

            </div><!--end postauthor-->';    
}
?>

以下是首选的解决方案:

代码语言:javascript
复制
<?php if (function_exists( 'wpsabox_author_box' ) ) {
            echo wpsabox_author_box();
        } else { ?>
         <div class="postauthor">
            <div class="authorprofilepix">
             <?php echo get_avatar( get_the_author_id() , 80 ); ?>
            </div>
            <div class="authorprofile">
                <h4><?php the_author(); ?></h4>
                <p><?php the_author_description(); ?></p>
            </div>
            <div class="clearfix"></div>

        </div><!--end postauthor-->

   <?php     }

 ?>

正如你所看到的,它稍微修正了Ravi的解决方案。我不能说它更好,但我更喜欢它,因为它更清楚。

还有一件事。不要使用the_author_description()函数,请使用the_author_meta('description')函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38143917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档