comments-page.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /*
  3. Template Name: Comments page
  4. */
  5. $limit = 25; /* Comments per Page */
  6. function get_url_var($name) {
  7. $strURL = $_SERVER['REQUEST_URI'];
  8. $arrVals = split("/",$strURL);
  9. $found = 0;
  10. foreach ($arrVals as $index => $value) {
  11. if($value == $name)
  12. $found = $index;
  13. }
  14. $place = $found + 1;
  15. return $arrVals[$place];
  16. }
  17. /* return thumbnail url and image find url for first image of a given post */
  18. function get_comment_thumb_full ( $post_id ) {
  19. $images = get_attached_media('image', $post_id);
  20. $thumbsrc = '';
  21. $fullsrc = '';
  22. foreach($images as $image) {
  23. # $thumbsrc = wp_get_attachment_image_src($image->ID,'optics-mws-gallery-thumb')[0];
  24. $thumbsrc = wp_get_attachment_image_src($image->ID,'thumbnail')[0];
  25. $fullsrc = wp_get_attachment_image_src($image->ID,'full')[0];
  26. break;
  27. }
  28. return [$thumbsrc, $fullsrc];
  29. }
  30. $page = get_query_var('comments');
  31. $offset = (intval($page) * $limit) - $limit;
  32. if ( $offset < 0 ) {
  33. $offset = 0;
  34. }
  35. $param = array( 'status' => 'approve',
  36. 'offset' => $offset,
  37. 'number' => $limit );
  38. $total_comments = get_comments( array( 'status' => 'approve' ) );
  39. $pages = ceil( count( $total_comments ) / $limit );
  40. $comments = get_comments( $param );
  41. get_header(); ?>
  42. <div id="content" class="site-content">
  43. <div id="primary" class="content-area">
  44. <main id="main" class="site-main" role="main">
  45. <article id="comments-page" class="comments-page page type-page status-publish hentry entry">
  46. <header class="entry-header alignwide">
  47. <h2 class="entry-title">Comments</h1>
  48. </header>
  49. <div class="entry-content">
  50. <?php
  51. foreach( $comments as $comment ) {
  52. $post_id = $comment->comment_post_ID;
  53. if ( $old_post_id && $old_post_id == $post_id) {
  54. echo " <div class='entry-summary'>\n";
  55. if ($comment->comment_author == 'Markus Spring') {
  56. echo " <strong><a href='{$comment->comment_author_url}' class='owner' "
  57. . "target='_blank'>{$comment->comment_author}</a></strong>\n";
  58. } else {
  59. echo " <strong><a href='{$comment->comment_author_url}'"
  60. . "target='_blank'>{$comment->comment_author}</a></strong>\n";
  61. }
  62. echo " said at {$comment->comment_date}:<br />{$comment->comment_content}\n";
  63. echo "</div><!-- .entry-summary -->\n";
  64. } else {
  65. if ($old_post_id) {
  66. echo "<br style='clear: both;' /><hr class='comment-sep' />\n";
  67. }
  68. $old_post_id = $post_id;
  69. list( $thumbsrc, $fullsrc ) = get_comment_thumb_full( $post_id );
  70. if ( $thumbsrc ) {
  71. echo "<div class='wp-block-image' style='margin-bottom: 5px !important;'>"
  72. . "<a href='" . get_permalink($post_id)
  73. . "'><figure class='alignleft size-thumbnail'>"
  74. . "<img loading='lazy' width='268' height='268' "
  75. . "src='" . $thumbsrc . "' alt='' class='wp-image-comments'/></figure></a></div>\n";
  76. echo "<h4 style='display: inline;'>On&nbsp;<a href='" . get_permalink($post_id) . "'>"
  77. . get_the_title($post_id) . "</a></h4>\n";
  78. } else {
  79. echo " On '" . get_the_title($post_id) . "',<br />";
  80. }
  81. echo " <div class='entry-summary'>\n";
  82. if ($comment->comment_author == 'Markus Spring') {
  83. echo " <strong><a href='{$comment->comment_author_url}' class='owner' "
  84. . "target='_blank'>{$comment->comment_author}</a></strong>\n";
  85. } else {
  86. echo " <strong><a href='{$comment->comment_author_url}'"
  87. . "target='_blank'>{$comment->comment_author}</a></strong>\n";
  88. }
  89. /* echo " said at {$comment->comment_date}:<br />{$comment->comment_content}\n"; */
  90. echo " said at {$comment->comment_date}:<br />"
  91. . apply_filters('the_content', $comment->comment_content) . "\n";
  92. echo " </div><!-- .entry-summary -->\n";
  93. }
  94. }
  95. ?>
  96. <footer class="entry-footer">
  97. <?php //optics_entry_footer(); ?>
  98. </footer><!-- .entry-footer -->
  99. </div><!-- end search-result -->
  100. </article><!-- #post-## -->
  101. <?php
  102. /* get_sidebar();
  103. get_footer(); */
  104. ?>