我不太精通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-->');
}
?>在期待中感谢!
发布于 2016-07-01 19:15:30
您应该在echo调用内的字符串和函数调用之间添加点。
例如:
echo ('string' . function() . ' string ');发布于 2016-07-01 19:20:24
使用以下方法:
<?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 }
?>发布于 2016-07-01 20:08:30
下面是你的代码应该是什么样子才能工作:
<?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 }
?>正如你所看到的,它稍微修正了Ravi的解决方案。我不能说它更好,但我更喜欢它,因为它更清楚。
还有一件事。不要使用the_author_description()函数,请使用the_author_meta('description')函数。
https://stackoverflow.com/questions/38143917
复制相似问题