1
WPの5番目のコメントの後にHTMLコードを挿入したい(5つ以上のコメントがある場合)。WPコメントの間にHTMLコードを挿入
私はコーディングにうまくいかず、私は似たような話題が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、ハッピーコーディング –