comments.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * The template file for displaying the comments and comment form for the
  4. * Twenty Twenty theme.
  5. *
  6. * @package WordPress
  7. * @subpackage Twenty_Twenty
  8. * @since Twenty Twenty 1.0
  9. */
  10. /*
  11. * If the current post is protected by a password and
  12. * the visitor has not yet entered the password we will
  13. * return early without loading the comments.
  14. */
  15. if ( post_password_required() ) {
  16. return;
  17. }
  18. if ( $comments ) {
  19. ?>
  20. <div class="comments" id="comments">
  21. <?php
  22. $comments_number = absint( get_comments_number() );
  23. ?>
  24. <div class="comments-header section-inner small max-percentage">
  25. <h2 class="comment-reply-title">
  26. <?php
  27. if ( ! have_comments() ) {
  28. _e( 'Leave a comment', 'twentytwenty' );
  29. } elseif ( '1' === $comments_number ) {
  30. /* translators: %s: Post title. */
  31. printf( _x( 'One reply on &ldquo;%s&rdquo;', 'comments title', 'twentytwenty' ), get_the_title() );
  32. } else {
  33. printf(
  34. /* translators: 1: Number of comments, 2: Post title. */
  35. _nx(
  36. '%1$s reply on &ldquo;%2$s&rdquo;',
  37. '%1$s replies on &ldquo;%2$s&rdquo;',
  38. $comments_number,
  39. 'comments title',
  40. 'twentytwenty'
  41. ),
  42. number_format_i18n( $comments_number ),
  43. get_the_title()
  44. );
  45. }
  46. ?>
  47. </h2><!-- .comments-title -->
  48. </div><!-- .comments-header -->
  49. <div class="comments-inner section-inner thin max-percentage">
  50. <?php
  51. wp_list_comments(
  52. array(
  53. 'walker' => new TwentyTwenty_Walker_Comment(),
  54. 'avatar_size' => 120,
  55. 'style' => 'div',
  56. )
  57. );
  58. $comment_pagination = paginate_comments_links(
  59. array(
  60. 'echo' => false,
  61. 'end_size' => 0,
  62. 'mid_size' => 0,
  63. 'next_text' => __( 'Newer Comments', 'twentytwenty' ) . ' <span aria-hidden="true">&rarr;</span>',
  64. 'prev_text' => '<span aria-hidden="true">&larr;</span> ' . __( 'Older Comments', 'twentytwenty' ),
  65. )
  66. );
  67. if ( $comment_pagination ) {
  68. $pagination_classes = '';
  69. // If we're only showing the "Next" link, add a class indicating so.
  70. if ( false === strpos( $comment_pagination, 'prev page-numbers' ) ) {
  71. $pagination_classes = ' only-next';
  72. }
  73. ?>
  74. <nav class="comments-pagination pagination<?php echo $pagination_classes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static output ?>" aria-label="<?php esc_attr_e( 'Comments', 'twentytwenty' ); ?>">
  75. <?php echo wp_kses_post( $comment_pagination ); ?>
  76. </nav>
  77. <?php
  78. }
  79. ?>
  80. </div><!-- .comments-inner -->
  81. </div><!-- comments -->
  82. <?php
  83. }
  84. if ( comments_open() || pings_open() ) {
  85. if ( $comments ) {
  86. echo '<hr class="styled-separator is-style-wide" aria-hidden="true" />';
  87. }
  88. comment_form(
  89. array(
  90. 'class_form' => 'section-inner thin max-percentage',
  91. 'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
  92. 'title_reply_after' => '</h2>',
  93. )
  94. );
  95. } elseif ( is_single() ) {
  96. if ( $comments ) {
  97. echo '<hr class="styled-separator is-style-wide" aria-hidden="true" />';
  98. }
  99. ?>
  100. <div class="comment-respond" id="respond">
  101. <p class="comments-closed"><?php _e( 'Comments are closed.', 'twentytwenty' ); ?></p>
  102. </div><!-- #respond -->
  103. <?php
  104. }