|
1 |
| -<?php |
2 |
| -/** |
3 |
| - * The template for displaying comments |
4 |
| - * |
5 |
| - * This is the template that displays the area of the page that contains both the current comments |
6 |
| - * and the comment form. |
7 |
| - * |
8 |
| - * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ |
9 |
| - * |
10 |
| - * @package cjt |
11 |
| - */ |
12 |
| - |
13 |
| -/* |
14 |
| - * If the current post is protected by a password and |
15 |
| - * the visitor has not yet entered the password we will |
16 |
| - * return early without loading the comments. |
17 |
| - */ |
18 |
| -if (post_password_required()) { |
19 |
| - return; |
20 |
| -} |
21 |
| -?> |
22 |
| - |
23 |
| -<div id="comments" class="comments-area"> |
24 |
| - |
25 |
| - <?php |
26 |
| - // You can start editing here -- including this comment! |
27 |
| - if (have_comments()) : |
28 |
| - ?> |
29 |
| - <h2 class="comments-title"> |
30 |
| - <?php |
31 |
| - $cjt_comment_count = get_comments_number(); |
32 |
| - if ('1' === $cjt_comment_count) { |
33 |
| - printf( |
34 |
| - /* translators: 1: title. */ |
35 |
| - esc_html__('One thought on “%1$s”', 'cjt'), |
36 |
| - '<span>' . wp_kses_post(get_the_title()) . '</span>' |
37 |
| - ); |
38 |
| - } else { |
39 |
| - printf( |
40 |
| - /* translators: 1: comment count number, 2: title. */ |
41 |
| - esc_html(_nx('%1$s thought on “%2$s”', '%1$s thoughts on “%2$s”', $cjt_comment_count, 'comments title', 'cjt')), |
42 |
| - number_format_i18n($cjt_comment_count), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
43 |
| - '<span>' . wp_kses_post(get_the_title()) . '</span>' |
44 |
| - ); |
45 |
| - } |
46 |
| - ?> |
47 |
| - </h2><!-- .comments-title --> |
48 |
| - |
49 |
| - <?php the_comments_navigation(); ?> |
50 |
| - |
51 |
| - <ol class="comment-list"> |
52 |
| - <?php |
53 |
| - wp_list_comments( |
54 |
| - array( |
55 |
| - 'style' => 'ol', |
56 |
| - 'short_ping' => true, |
57 |
| - ) |
58 |
| - ); |
59 |
| - ?> |
60 |
| - </ol><!-- .comment-list --> |
61 |
| - |
62 |
| - <?php |
63 |
| - the_comments_navigation(); |
64 |
| - |
65 |
| - // If comments are closed and there are comments, let's leave a little note, shall we? |
66 |
| - if (! comments_open()) : |
67 |
| - ?> |
68 |
| - <p class="no-comments"> |
69 |
| - <?php esc_html_e('Comments are closed.', 'cjt'); ?> |
70 |
| - </p> |
71 |
| - <?php |
72 |
| - endif; |
73 |
| - |
74 |
| - endif; // Check for have_comments(). |
75 |
| - |
76 |
| - comment_form(); |
77 |
| - ?> |
78 |
| - |
79 |
| -</div><!-- #comments --> |
| 1 | +<?php |
| 2 | +/** |
| 3 | + * The template for displaying comments |
| 4 | + * |
| 5 | + * This is the template that displays the area of the page that contains both the current comments |
| 6 | + * and the comment form. |
| 7 | + * |
| 8 | + * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ |
| 9 | + * |
| 10 | + * @package cjt |
| 11 | + */ |
| 12 | + |
| 13 | +/* |
| 14 | + * If the current post is protected by a password and |
| 15 | + * the visitor has not yet entered the password we will |
| 16 | + * return early without loading the comments. |
| 17 | + */ |
| 18 | +if (post_password_required()) { |
| 19 | + return; |
| 20 | +} |
| 21 | +?> |
| 22 | + |
| 23 | +<div id="comments" class="comments-area bg-white rounded shadow-lg p-8 mt-8"> |
| 24 | + <div class="max-w-3xl mx-auto"> |
| 25 | + <?php |
| 26 | + if (have_comments()) : |
| 27 | + $cjt_comment_count = get_comments_number(); |
| 28 | + ?> |
| 29 | + <h2 class="comments-title text-2xl font-bold mb-6"> |
| 30 | + <?php |
| 31 | + if ('1' === $cjt_comment_count) { |
| 32 | + printf( |
| 33 | + /* translators: 1: title. */ |
| 34 | + esc_html__('One thought on “%1$s”', 'cjt'), |
| 35 | + '<span class="font-normal">' . wp_kses_post(get_the_title()) . '</span>' |
| 36 | + ); |
| 37 | + } else { |
| 38 | + printf( |
| 39 | + /* translators: 1: comment count number, 2: title. */ |
| 40 | + esc_html(_nx('%1$s thought on “%2$s”', '%1$s thoughts on “%2$s”', $cjt_comment_count, 'comments title', 'cjt')), |
| 41 | + number_format_i18n($cjt_comment_count), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 42 | + '<span class="font-normal">' . wp_kses_post(get_the_title()) . '</span>' |
| 43 | + ); |
| 44 | + } |
| 45 | + ?> |
| 46 | + </h2> |
| 47 | + |
| 48 | + <?php the_comments_navigation(array( |
| 49 | + 'prev_text' => '<span class="text-brand-blue hover:text-brand-blue/80">← ' . __('Older Comments', 'cjt') . '</span>', |
| 50 | + 'next_text' => '<span class="text-brand-blue hover:text-brand-blue/80">' . __('Newer Comments', 'cjt') . ' →</span>', |
| 51 | + )); ?> |
| 52 | + |
| 53 | + <ul class="comment-list space-y-6 mb-6"> |
| 54 | + <?php |
| 55 | + wp_list_comments(array( |
| 56 | + 'style' => 'ul', |
| 57 | + 'short_ping' => true, |
| 58 | + 'callback' => 'cjt_custom_comment_output' |
| 59 | + )); |
| 60 | + ?> |
| 61 | + </ul> |
| 62 | + |
| 63 | + <?php |
| 64 | + the_comments_navigation(array( |
| 65 | + 'prev_text' => '<span class="text-brand-blue hover:text-brand-blue/80">← ' . __('Older Comments', 'cjt') . '</span>', |
| 66 | + 'next_text' => '<span class="text-brand-blue hover:text-brand-blue/80">' . __('Newer Comments', 'cjt') . ' →</span>', |
| 67 | + )); |
| 68 | + |
| 69 | + if (!comments_open()) : |
| 70 | + ?> |
| 71 | + <p class="no-comments bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4 mb-6"> |
| 72 | + <?php esc_html_e('Comments are closed.', 'cjt'); ?> |
| 73 | + </p> |
| 74 | + <?php |
| 75 | + endif; |
| 76 | + |
| 77 | + endif; // Check for have_comments(). |
| 78 | + |
| 79 | + comment_form(array( |
| 80 | + 'class_form' => 'space-y-4', |
| 81 | + 'class_submit' => 'bg-brand-blue hover:bg-brand-blue/80 text-white font-bold py-2 px-4 rounded', |
| 82 | + 'comment_field' => '<div class="comment-form-comment"> |
| 83 | + <label for="comment" class="block text-sm font-medium text-gray-700 mb-1">' . _x('Comment', 'noun') . '</label> |
| 84 | + <textarea id="comment" name="comment" rows="5" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-brand-blue/30 focus:ring focus:ring-brand-blue/20 focus:ring-opacity-50" required></textarea> |
| 85 | + </div>', |
| 86 | + 'fields' => array( |
| 87 | + 'author' => '<div class="comment-form-author"> |
| 88 | + <label for="author" class="block text-sm font-medium text-gray-700 mb-1">' . __('Name', 'cjt') . '</label> |
| 89 | + <input type="text" id="author" name="author" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50" required> |
| 90 | + </div>', |
| 91 | + 'email' => '<div class="comment-form-email"> |
| 92 | + <label for="email" class="block text-sm font-medium text-gray-700 mb-1">' . __('Email', 'cjt') . '</label> |
| 93 | + <input type="email" id="email" name="email" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50" required> |
| 94 | + </div>', |
| 95 | + 'url' => '<div class="comment-form-url"> |
| 96 | + <label for="url" class="block text-sm font-medium text-gray-700 mb-1">' . __('Website', 'cjt') . '</label> |
| 97 | + <input type="url" id="url" name="url" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-300 focus:ring focus:ring-blue-200 focus:ring-opacity-50"> |
| 98 | + </div>', |
| 99 | + ), |
| 100 | + 'title_reply_before' => '<h3 id="reply-title" class="comment-reply-title text-xl font-bold mb-4">', |
| 101 | + 'title_reply_after' => '</h3>', |
| 102 | + )); |
| 103 | + ?> |
| 104 | + </div> |
| 105 | +</div> |
| 106 | + |
| 107 | +<?php |
| 108 | +// Custom comment output function |
| 109 | +function cjt_custom_comment_output($comment, $args, $depth) { |
| 110 | + $GLOBALS['comment'] = $comment; |
| 111 | + ?> |
| 112 | + <li id="comment-<?php comment_ID(); ?>" <?php comment_class('bg-gray-50 p-4 rounded-lg'); ?>> |
| 113 | + <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
| 114 | + <footer class="comment-meta mb-2"> |
| 115 | + <div class="comment-author vcard flex items-center"> |
| 116 | + <?php echo get_avatar($comment, 40, '', '', array('class' => 'rounded-full mr-2')); ?> |
| 117 | + <?php printf('<b class="fn">%s</b>', get_comment_author_link()); ?> |
| 118 | + </div> |
| 119 | + <div class="comment-metadata text-sm text-gray-500 mt-1"> |
| 120 | + <time datetime="<?php comment_time('c'); ?>"> |
| 121 | + <?php printf(_x('%1$s at %2$s', '1: date, 2: time'), get_comment_date(), get_comment_time()); ?> |
| 122 | + </time> |
| 123 | + <?php edit_comment_link(__('Edit'), ' <span class="mx-1">|</span> <span class="edit-link">', '</span>'); ?> |
| 124 | + </div> |
| 125 | + </footer> |
| 126 | + <div class="comment-content prose mt-2"> |
| 127 | + <?php comment_text(); ?> |
| 128 | + </div> |
| 129 | + <div class="reply mt-2"> |
| 130 | + <?php |
| 131 | + comment_reply_link(array_merge($args, array( |
| 132 | + 'add_below' => 'div-comment', |
| 133 | + 'depth' => $depth, |
| 134 | + 'max_depth' => $args['max_depth'], |
| 135 | + 'before' => '<div class="reply">', |
| 136 | + 'after' => '</div>', |
| 137 | + 'class' => 'text-brand-blue hover:text-brand-blue/50' |
| 138 | + ))); |
| 139 | + ?> |
| 140 | + </div> |
| 141 | + </article> |
| 142 | + </li> |
| 143 | + <?php |
| 144 | +} |
| 145 | +?> |
0 commit comments