1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The template for displaying comments. |
4
|
|
|
* |
5
|
|
|
* The area of the page that contains both current comments |
6
|
|
|
* and the comment form. |
7
|
|
|
* |
8
|
|
|
* @package spurs |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
// Exit if accessed directly. |
12
|
|
|
defined( 'ABSPATH' ) || exit; |
13
|
|
|
|
14
|
|
|
/* |
15
|
|
|
* If the current post is protected by a password and |
16
|
|
|
* the visitor has not yet entered the password we will |
17
|
|
|
* return early without loading the comments. |
18
|
|
|
*/ |
19
|
|
|
if ( post_password_required() ) { |
20
|
|
|
return; |
21
|
|
|
} |
22
|
|
|
?> |
23
|
|
|
|
24
|
|
|
<div class="comments-area" id="comments"> |
25
|
|
|
<div class="entry-content"> |
26
|
|
|
<?php // You can start editing here -- including this comment! ?> |
27
|
|
|
|
28
|
|
|
<?php if ( have_comments() ) : ?> |
29
|
|
|
|
30
|
|
|
<h2 class="comments-title"> |
31
|
|
|
|
32
|
|
|
<?php |
33
|
|
|
$comments_number = get_comments_number(); |
34
|
|
|
if ( 1 === (int) $comments_number ) { |
35
|
|
|
printf( |
36
|
|
|
/* translators: %s: post title */ |
37
|
|
|
esc_html_x( 'One thought on “%s”', 'comments title', 'spurs' ), |
38
|
|
|
'<span>' . get_the_title() . '</span>' |
39
|
|
|
); |
40
|
|
|
} else { |
41
|
|
|
printf( // WPCS: XSS OK. |
42
|
|
|
/* translators: 1: number of comments, 2: post title */ |
43
|
|
|
esc_html( _nx( |
44
|
|
|
'%1$s thought on “%2$s”', |
45
|
|
|
'%1$s thoughts on “%2$s”', |
46
|
|
|
$comments_number, |
47
|
|
|
'comments title', |
48
|
|
|
'spurs' |
49
|
|
|
) ), |
50
|
|
|
number_format_i18n( $comments_number ), |
51
|
|
|
'<span>' . get_the_title() . '</span>' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
?> |
55
|
|
|
|
56
|
|
|
</h2><!-- .comments-title --> |
57
|
|
|
|
58
|
|
View Code Duplication |
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through. ?> |
|
|
|
|
59
|
|
|
|
60
|
|
|
<nav class="comment-navigation" id="comment-nav-above"> |
61
|
|
|
|
62
|
|
|
<h1 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'spurs' ); ?></h1> |
63
|
|
|
|
64
|
|
|
<?php if ( get_previous_comments_link() ) { ?> |
65
|
|
|
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', |
66
|
|
|
'spurs' ) ); ?></div> |
67
|
|
|
<?php } |
68
|
|
|
if ( get_next_comments_link() ) { ?> |
69
|
|
|
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', |
70
|
|
|
'spurs' ) ); ?></div> |
71
|
|
|
<?php } ?> |
72
|
|
|
|
73
|
|
|
</nav><!-- #comment-nav-above --> |
74
|
|
|
|
75
|
|
|
<?php endif; // check for comment navigation. ?> |
76
|
|
|
|
77
|
|
|
<ol class="comment-list" style="list-style: none"> |
78
|
|
|
<?php |
79
|
|
|
wp_list_comments( array( |
80
|
|
|
'style' => 'ol', |
81
|
|
|
'short_ping' => true, |
82
|
|
|
) ); |
83
|
|
|
?> |
84
|
|
|
</ol><!-- .comment-list --> |
85
|
|
|
|
86
|
|
View Code Duplication |
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through. ?> |
|
|
|
|
87
|
|
|
|
88
|
|
|
<nav class="comment-navigation" id="comment-nav-below"> |
89
|
|
|
|
90
|
|
|
<h1 class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'spurs' ); ?></h1> |
91
|
|
|
|
92
|
|
|
<?php if ( get_previous_comments_link() ) { ?> |
93
|
|
|
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', |
94
|
|
|
'spurs' ) ); ?></div> |
95
|
|
|
<?php } |
96
|
|
|
if ( get_next_comments_link() ) { ?> |
97
|
|
|
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', |
98
|
|
|
'spurs' ) ); ?></div> |
99
|
|
|
<?php } ?> |
100
|
|
|
|
101
|
|
|
</nav><!-- #comment-nav-below --> |
102
|
|
|
|
103
|
|
|
<?php endif; // check for comment navigation. ?> |
104
|
|
|
|
105
|
|
|
<?php endif; // endif have_comments(). ?> |
106
|
|
|
|
107
|
|
|
<?php |
108
|
|
|
// If comments are closed and there are comments, let's leave a little note, shall we? |
109
|
|
|
if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) : ?> |
110
|
|
|
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'spurs' ); ?></p> |
111
|
|
|
<?php endif; ?> |
112
|
|
|
|
113
|
|
|
<?php comment_form(); // Render comments form. ?> |
114
|
|
|
</div> |
115
|
|
|
</div><!-- #comments --> |
116
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.