【发布时间】:2018-03-16 11:00:45
【问题描述】:
我想在 WP 中的每 5 条评论之后/下方插入 HTML 代码(如果有 > 5 个 cmets)。
我不擅长编码,我只找到了 1 个类似的主题,没有得到回答。
问题是 - 如何在每 5 条评论后插入广告/代码?
我不擅长 PHP(非常基本的经验)...如果可能,请提供完整的代码 - 谢谢!
这是显示 cmets 的函数(来自 functions.php):
if ( ! function_exists( 'mts_comments' ) ) {
function mts_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>" style="position:relative;" itemscope itemtype="http://schema.org/UserComments">
<div class="comment-author vcard">
<?php echo get_avatar( $comment->comment_author_email, 70 ); ?>
<div class="comment-metadata">
<?php printf('<span class="fn" itemprop="creator" itemscope itemtype="http://schema.org/Person">%s</span>', get_comment_author_link()) ?>
<time><?php comment_date(get_option( 'date_format' )); ?></time>
<span class="comment-meta">
<?php edit_comment_link(__('(Edit)', 'point'),' ','') ?>
</span>
<span class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</span>
</div>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.', 'point') ?></em>
<br />
<?php endif; ?>
<div class="commentmetadata" itemprop="commentText">
<?php comment_text() ?>
</div>
</div>
</li>
<?php }
}
到目前为止,我想出了如何获得 Approved cmets 的计数。这是我的“代码”:
$cmPostId = get_the_ID();
$comments_count = wp_count_comments($cmPostId);
$commApproved = $comments_count->approved;
代码示例:<div>HTML HERE</div>
我感谢任何和所有的帮助。提前致谢!
【问题讨论】:
标签: php wordpress foreach wordpress-theming