1
我想在WP中的每個第5條評論之後插入HTML代碼(如果有> 5條評論)。在WP評論之間插入HTML代碼
我不是很好的t編碼,我只找到1個類似的話題,沒有回答。
問題是 - 如何在每第5條評論後插入廣告/代碼?
我不擅長PHP(非常基本的經驗)...如果可能,請提供完整的代碼 - 謝謝!
這裏是我的功能(從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 }
}
到目前爲止,我想通了,如何獲得批准的評論數。這裏是我的 「代碼」:
$cmPostId = get_the_ID();
$comments_count = wp_count_comments($cmPostId);
$commApproved = $comments_count->approved;
代碼examle:<div>HTML HERE</div>
我明白任何及所有的幫助。提前致謝!
了巨大的成功,謝謝大家! – Levchik
np,開心編碼 –