comments.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 WordPress
  11. * @subpackage Twenty_Nineteen
  12. * @since 1.0.0
  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. $discussion = twentynineteen_get_discussion_data();
  23. ?>
  24. <div id="comments" class="<?php echo comments_open() ? 'comments-area' : 'comments-area comments-closed'; ?>">
  25. <div class="<?php echo $discussion->responses > 0 ? 'comments-title-wrap' : 'comments-title-wrap no-responses'; ?>">
  26. <h2 class="comments-title">
  27. <?php
  28. if ( comments_open() ) {
  29. if ( have_comments() ) {
  30. _e( 'Join the Conversation', 'twentynineteen' );
  31. } else {
  32. _e( 'Leave a comment', 'twentynineteen' );
  33. }
  34. } else {
  35. if ( '1' == $discussion->responses ) {
  36. /* translators: %s: Post title. */
  37. printf( _x( 'One reply on &ldquo;%s&rdquo;', 'comments title', 'twentynineteen' ), get_the_title() );
  38. } else {
  39. printf(
  40. /* translators: 1: Number of comments, 2: Post title. */
  41. _nx(
  42. '%1$s reply on &ldquo;%2$s&rdquo;',
  43. '%1$s replies on &ldquo;%2$s&rdquo;',
  44. $discussion->responses,
  45. 'comments title',
  46. 'twentynineteen'
  47. ),
  48. number_format_i18n( $discussion->responses ),
  49. get_the_title()
  50. );
  51. }
  52. }
  53. ?>
  54. </h2><!-- .comments-title -->
  55. <?php
  56. // Only show discussion meta information when comments are open and available.
  57. if ( have_comments() && comments_open() ) {
  58. get_template_part( 'template-parts/post/discussion', 'meta' );
  59. }
  60. ?>
  61. </div><!-- .comments-title-flex -->
  62. <?php
  63. if ( have_comments() ) :
  64. // Show comment form at top if showing newest comments at the top.
  65. if ( comments_open() ) {
  66. twentynineteen_comment_form( 'desc' );
  67. }
  68. ?>
  69. <ol class="comment-list">
  70. <?php
  71. wp_list_comments(
  72. array(
  73. 'walker' => new TwentyNineteen_Walker_Comment(),
  74. 'avatar_size' => twentynineteen_get_avatar_size(),
  75. 'short_ping' => true,
  76. 'style' => 'ol',
  77. )
  78. );
  79. ?>
  80. </ol><!-- .comment-list -->
  81. <?php
  82. // Show comment navigation
  83. if ( have_comments() ) :
  84. $prev_icon = twentynineteen_get_icon_svg( 'chevron_left', 22 );
  85. $next_icon = twentynineteen_get_icon_svg( 'chevron_right', 22 );
  86. $comments_text = __( 'Comments', 'twentynineteen' );
  87. the_comments_navigation(
  88. array(
  89. 'prev_text' => sprintf( '%s <span class="nav-prev-text"><span class="primary-text">%s</span> <span class="secondary-text">%s</span></span>', $prev_icon, __( 'Previous', 'twentynineteen' ), __( 'Comments', 'twentynineteen' ) ),
  90. 'next_text' => sprintf( '<span class="nav-next-text"><span class="primary-text">%s</span> <span class="secondary-text">%s</span></span> %s', __( 'Next', 'twentynineteen' ), __( 'Comments', 'twentynineteen' ), $next_icon ),
  91. )
  92. );
  93. endif;
  94. // Show comment form at bottom if showing newest comments at the bottom.
  95. if ( comments_open() && 'asc' === strtolower( get_option( 'comment_order', 'asc' ) ) ) :
  96. ?>
  97. <div class="comment-form-flex">
  98. <span class="screen-reader-text"><?php _e( 'Leave a comment', 'twentynineteen' ); ?></span>
  99. <?php twentynineteen_comment_form( 'asc' ); ?>
  100. <h2 class="comments-title" aria-hidden="true"><?php _e( 'Leave a comment', 'twentynineteen' ); ?></h2>
  101. </div>
  102. <?php
  103. endif;
  104. // If comments are closed and there are comments, let's leave a little note, shall we?
  105. if ( ! comments_open() ) :
  106. ?>
  107. <p class="no-comments">
  108. <?php _e( 'Comments are closed.', 'twentynineteen' ); ?>
  109. </p>
  110. <?php
  111. endif;
  112. else :
  113. // Show comment form.
  114. twentynineteen_comment_form( true );
  115. endif; // if have_comments();
  116. ?>
  117. </div><!-- #comments -->