编写此php条件语句的正确方法
我不是很精通php,因为我是一个新手。我正试图使用这些代码行,但出现了错误。写这个的正确方式是什么:编写此php条件语句的正确方法,php,wordpress,Php,Wordpress,我不是很精通php,因为我是一个新手。我正试图使用这些代码行,但出现了错误。写这个的正确方式是什么: <?php if ( function_exists( 'wpsabox_author_box' ) ) { echo wpsabox_author_box(); } else { echo ( '<div class="postauthor"> <div class="authorprofilep
<?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-->');
}
?>
您应该在echo调用中的字符串和函数调用之间添加点
e、 g
您应该在echo调用中的字符串和函数调用之间添加点
e、 g
这样做:
<?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 }
?>
'
使用以下方法:
<?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 }
?>
'
以下是您的代码应该如何运行:
<?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-->';
}
?>
以下是首选的解决方案:
<?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 }
?>
正如你所看到的,它稍微修正了拉维的解。我不能说它更好,但我更喜欢它,因为它更清晰
还有一件事。不要使用author\u description()
函数,而是使用author\u meta('description')
。以下是代码的外观:
<?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-->';
}
?>
以下是首选的解决方案:
<?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 }
?>
正如你所看到的,它稍微修正了拉维的解。我不能说它更好,但我更喜欢它,因为它更清晰
还有一件事。不要使用author\u description()
函数,而是使用author\u meta('description')
。使用逗号避免字符串连接。另外,使用get_the_author_meta(),因为get_the_author_id()和_author_description()都已被弃用
if ( function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else {
echo '<div class="postauthor">
<div class="authorprofilepix">',
get_avatar( get_the_author_meta('ID') , 80 ),
'</div>
<div class="authorprofile">
<h4>', get_the_author(), '</h4>
<p>', get_the_author_meta('description'), '</p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->';
}
if(函数存在('wpsabox\u author\u box')){
echo wpsabox_author_box();
}否则{
回声'
',
获取化身(获取作者元('ID'),80),
'
“,获取作者(),”
,获取作者元('description'),'
';
}
使用逗号避免字符串连接。另外,使用get_the_author_meta(),因为get_the_author_id()和_author_description()都已被弃用
if ( function_exists( 'wpsabox_author_box' ) ) {
echo wpsabox_author_box();
} else {
echo '<div class="postauthor">
<div class="authorprofilepix">',
get_avatar( get_the_author_meta('ID') , 80 ),
'</div>
<div class="authorprofile">
<h4>', get_the_author(), '</h4>
<p>', get_the_author_meta('description'), '</p>
</div>
<div class="clearfix"></div>
</div><!--end postauthor-->';
}
if(函数存在('wpsabox\u author\u box')){
echo wpsabox_author_box();
}否则{
回声'
',
获取化身(获取作者元('ID'),80),
'
“,获取作者(),”
,获取作者元('description'),'
';
}
你得到了什么错误?你需要点
来连接字符串。@VinodVT正如我在对你现在删除的答案的评论中所说的,那根本不是真的好吧,我将删除该评论你得到了什么错误?你需要点
来连接字符串。@VinodVT正如我在对你现在删除的答案的评论中所说的,那根本不是真的好吧,我会删除那条评论删除分号删除分号