スニペット/WordPress comments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | function bones_comments($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?> <div id="comment-<?php comment_ID(); ?>" <?php comment_class('cf'); ?>> <article> <header> <?php $bgauthemail = get_comment_author_email(); ?> <?php printf(__('<cite class="comment-author">%1$s</cite> %2$s', 'bonestheme'), get_comment_author_link(), edit_comment_link(__('(Edit)', 'bonestheme'),' ','')) ?> <time><?php comment_date(__('Y/m/d', 'bonestheme')); ?> <?php comment_time(__('H:i:s', 'bonestheme')); ?></time> </header> <section> <?php comment_text() ?> </section> <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?> </article> <?php } // 入力欄の順番 function move_comment_field_to_bottom($fields) { $comment_field = $fields['comment']; unset($fields['comment']); $fields['comment'] = $comment_field; return $fields; } add_filter('comment_form_fields', 'move_comment_field_to_bottom'); // URL入力欄削除 function remove_comment_url_fields($fields) { unset($fields['url']); return $fields; } add_filter('comment_form_default_fields', 'remove_comment_url_fields'); // メールアドレス欄を空っぽに、名前欄にプレースホルダ function remove_comment_email_value($fields) { $fields['email'] = '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="" size="40" placeholder="必須でない"></p>'; $fields['author'] = '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" value="" size="40" placeholder="名無しの紳士"></p>'; return $fields; } add_filter('comment_form_default_fields', 'remove_comment_email_value'); // デフォルト文言変更 function custom_comment_form($args) { $args['title_reply'] = 'コメントを投稿する'; $args['comment_notes_before'] = '<p class="comment-notes">※コメント反映は月・水・金曜日に実行されます。<br>※メールアドレスは管理人だけに届き、サイトには表示されません。</p>'; $args['comment_field'] = '<p class="comment-form-comment"><label for="comment">' . _x('本文', 'noun') . '</label><textarea id="comment" name="comment" aria-required="true"></textarea></p>'; $args['label_submit'] = '送信する'; $args['cancel_reply_link'] = '返信をキャンセル'; return $args; } add_filter('comment_form_defaults', 'custom_comment_form'); // 投稿者名が無記名の場合 function rename_anonymous($author = '', $comment_ID = 0, $comment) { if (empty($comment->comment_author) && empty($comment->user_id)) { $author = '名無しの紳士'; } return $author; } add_filter('get_comment_author', 'rename_anonymous', 20, 3); // リンク別窓 function autoblank($text) { $return = str_replace('<a', '<a target="_blank"', $text); return $return; } add_filter('comment_text', 'autoblank'); // HTML無効化 function custom_comment_tags($data) { global $allowedtags; unset($allowedtags['a']); unset($allowedtags['abbr']); unset($allowedtags['acronym']); unset($allowedtags['b']); unset($allowedtags['div']); unset($allowedtags['cite']); unset($allowedtags['code']); unset($allowedtags['del']); unset($allowedtags['em']); unset($allowedtags['i']); unset($allowedtags['q']); unset($allowedtags['strike']); unset($allowedtags['strong']); return $data; } add_filter('comments_open', 'custom_comment_tags'); add_filter('pre_comment_approved', 'custom_comment_tags'); |
1 | <?php if (get_comments_number()): ?><span><?php comments_number('0', '1', '%'); ?>コメント</span><?php endif; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php $comments = get_comments(array('status' => 'approve', 'number' => 3)); foreach($comments as $comment): $post = get_post($comment->comment_post_ID); ?> <article> <a href="<?php the_permalink(); ?>"><ul> <li><?php the_post_thumbnail(); ?></li> <li><?php the_title(); ?></li> </ul></a> <dl> <dt><?php comment_author_link(); ?> <?php comment_date('Y/m/d'); ?> <?php comment_time('H:i:s'); ?></dt> <dd><?php comment_text(); ?></dd> </dl> </article> <?php endforeach; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <?php $page = get_query_var('page') ? get_query_var('page') : 1; // 今何ページ $count = 30; // 1ページに表示する件数 // ページ送りのため全コメント件数取得 $total_comments = count(get_comments(array('type'=>'comment')) ); $max_page = ceil($total_comments / $count); // 最大ページ数 $new_args = array( 'number' => $count, 'type' => 'comment', 'offset' => ($page - 1) * $count ); $unique_comments = get_comments($new_args); ?> <?php // 親の投稿ID echo $val->comment_post_ID; ?> <?php foreach($unique_comments as $val): ?> <article> <a href="<?php the_permalink($val->comment_post_ID); ?>"><ul> <li><?php echo (get_the_post_thumbnail($val->comment_post_ID, 'full')); ?></li> <li><?php echo(get_the_title($val->comment_post_ID)); ?></li> </ul></a> <dl> <dt><?php echo(get_comment_author($val->comment_ID)); ?> <?php echo(get_comment_date('Y/m/d H:i', $val->comment_ID)); ?></dt> <dd><?php echo $val->comment_content; ?></dd> </dl> </article> <?php endforeach; ?> <?php //ページ送り ?> <?php $current_page = get_the_permalink(); ?> <?php if ($max_page > 1): ?> <nav id="nav-comment" class="pager"> <ul> <?php while($i <= $max_page): ?> <li><a href="<?php echo($current_page); ?>/<?php echo($i); ?>" <?php if ($i == $page) echo("class=\"current\""); ?>><?php echo($i); ?></a></li> <?php $i++; ?> <?php endwhile; ?> </ul> <!-- /#nav-comment --></nav> <?php endif; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php if (post_password_required()) { return; } ?> <?php if (have_comments()) : ?> <h6 id="comments-title"><?php comments_number( __('No Comments', 'bonestheme'), __('1コメント', 'bonestheme'), __('%コメント', 'bonestheme'));?></h6> <section class="commentlist"> <?php wp_list_comments(array( 'style' => 'div', 'short_ping' => false, 'callback' => 'bones_comments', 'type' => 'all', 'reply_text' => __('返信', 'bonestheme'), 'reverse_top_level' => null )); ?> <!-- /.commentlist --></section> <?php endif; ?> <?php comment_form(); ?> |
コメントを投稿する