php WP - 评论

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WP - 评论相关的知识,希望对你有一定的参考价值。

<?php
//Get All comments on this post 
$args = array(
    'status' => 'approve',
    'post_id' => get_the_ID()
);
 
// The comment Query
 
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );

// Comment Loop
if ( $comments ) { ?>
   				<ol class="commentlist clearfix">
							<?php foreach ( $comments as $comment ): ?>
								<li class="comment even thread-even depth-1" id="li-comment-1">
									<div id="<?php echo $comment->comment_ID; ?>" class="comment-wrap clearfix">
										<div class="comment-meta">
											<div class="comment-author vcard">
												<span class="comment-avatar clearfix">
												<img alt="" src="http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=60" class="avatar avatar-60 photo avatar-default" height="60" width="60"></span>
											</div>
										</div>
										<div class="comment-content clearfix">
											<div class="comment-author"> <?php echo $comment->comment_author; ?>
												<span><?php echo $comment->comment_date_gmt ; ?></span>
											</div>
											<p><?php echo $comment->comment_content; ?></p>
										</div>
										<div class="clear"></div>
									</div>
								</li>
							<?php endforeach; ?>
							</ol><!-- .commentlist end -->
<?php
    } else {
    echo 'No comments .';
}
?>

<?php
//Comment Form
$fields =  array(
  'author' =>  '<div class="col_one_third">
				<label for="author">'.__('Name','woblog').' (*)</label>
				<input type="text" id="author" name="author" value="" 
				size="22" tabindex="1" class="sm-form-control" required></div>',
  'email' => '<div class="col_one_third">
				    <label for="email">Email (*)</label>
				    <input id="email" name="email" type="text" value="" size="22" tabindex="2" class="sm-form-control" required >
			    </div>',
  'url' => '<div class="col_one_third col_last">
										<label for="url">Website</label>
										<input id="url" name="url" type="text" value="" size="22" tabindex="3" class="sm-form-control" >
			</div>'
);
$comment_field = '<div class="col_full">
										<label for="comment">'.__('Comment','woblog').'</label>
										<textarea id="comment" name="comment" cols="58" rows="7" tabindex="4" class="sm-form-control" aria-required="true" required /></textarea>
									</div>';

$args_com_form = array('fields' => $fields , 
                       'comment_field' => $comment_field,
                        'class_submit' => 'button button-3d nomargin');
?>
	<div id="respond" class="clearfix">
    <?php
      comment_form( $args_com_form);
    ?>
  </div>
  
  <?php
  //Display comments
  comments_template();
  ?>
    

以上是关于php WP - 评论的主要内容,如果未能解决你的问题,请参考以下文章

自定义评论模板

WP评论系统更换小结(转)

如何使用 WP Rest API v2 创建评论?

Wordpress评论循环

html ralden - 谷歌 - 评论 - WP-头

css WP - 主题评论