如何在html中解析php

问题描述 投票:0回答:1

我试图将php查询解析为html,但在html页面上它显示了数组。

我的查询如下:$comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve') );

我尝试使用以下命令在html页面上打印它:$html .= $comments;

html wordpress
1个回答
0
投票

正如你从examples看到的那样。

正如Tom J Nowell评论的那样,你需要遍历每个评论并将评论附加到$ html。

$args = array(
    'status'  => 'approve',
    'post_id' => $post->ID,
);
$comments = get_comments( $args );

foreach ( $comments as $comment ) :
    $html .= $comment->comment_author . '<br />' . $comment->comment_content . '<br />';
endforeach;
© www.soinside.com 2019 - 2024. All rights reserved.