使用带有变量字符串声明的函数

时间:2015-11-07 20:15:24

标签: php wordpress

今天我在下面创建此功能,以显示有关用户,日期,帖子浏览量,评论等的一些帖子信息..但是当我在其他文件中调用函数时,请告诉我错误说Parse error: syntax error, unexpected '.' in C:\wamp\www\ype\wp-content\themes\yallanpe\functions.php on line 118请问如何我可以纠正这个错误

<?php
function YPE_show_post_info(
$post_user,
$post_tags,
$post_date,
$post_views,
$post_comments
) {

$post_user     = '<span class="dashicons dashicons-admin-users"></span>&nbsp;&nbsp;'.the_author_posts_link();.'&nbsp;&nbsp;';
$post_tags     = '<span class="dashicons dashicons-tag"></span>'.the_category('&nbsp; / &nbsp;');.'';
$post_date     = '<span class="dashicons dashicons-calendar-alt"></span>&nbsp;&nbsp;'.get_the_date(get_option('date_format'));.'&nbsp;&nbsp;';
$post_views    = '<span class="dashicons dashicons-visibility"></span>&nbsp;&nbsp;'.getPostViews(get_the_ID());.'&nbsp;&nbsp;';
$post_comments = '<span class="dashicons dashicons-admin-comments"></span>&nbsp;&nbsp;'.comments_number('0','1','%');.'';
?>
<p class="text-muted">
    <?php 
        echo $post_user;
        echo $post_tags;
        echo $post_date;
        echo $post_views;
        echo $post_comments;
    ?>
</p>
<?php
}
?>

1 个答案:

答案 0 :(得分:0)

那么它可以在.

之后生成;

试试这段代码:

<?php
function YPE_show_post_info(
$post_user,
$post_tags,
$post_date,
$post_views,
$post_comments
) {

$post_user     = '<span class="dashicons dashicons-admin-users"></span>&nbsp;&nbsp;'.the_author_posts_link().'&nbsp;&nbsp;';
$post_tags     = '<span class="dashicons dashicons-tag"></span>'.the_category('&nbsp; / &nbsp;').'';
$post_date     = '<span class="dashicons dashicons-calendar-alt"></span>&nbsp;&nbsp;'.get_the_date(get_option('date_format')).'&nbsp;&nbsp;';
$post_views    = '<span class="dashicons dashicons-visibility"></span>&nbsp;&nbsp;'.getPostViews(get_the_ID()).'&nbsp;&nbsp;';
$post_comments = '<span class="dashicons dashicons-admin-comments"></span>&nbsp;&nbsp;'.comments_number('0','1','%').'';
?>
<p class="text-muted">
    <?php 
        echo $post_user;
        echo $post_tags;
        echo $post_date;
        echo $post_views;
        echo $post_comments;
    ?>
</p>
<?php
}
?>