Guest User

Untitled

a guest
Feb 18th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.41 KB | None | 0 0
  1. //comments.php
  2. <!-- Comments -->
  3. <div class="blog-recent-comments panel panel-default margin-bottom-30">
  4.     <a name="comments"></a>
  5.     <div class="panel-heading">
  6.         <h3>
  7.             <a href="#respond">Reply</a>&nbsp;-&nbsp;
  8.             <?php
  9.                 global $cpage;
  10.  
  11.                 $comment_page = $cpage;
  12.                 if( $comment_page == '' ) $comment_page=1;
  13.                 echo comments_number(); ?>
  14.         </h3>
  15.     </div>
  16.     <ul class="list-group">
  17.  
  18.         <?php
  19.             if ( have_comments() ) :
  20.                 echo $cpage;
  21.                 $comments_per_page = get_option('comments_per_page');
  22.                 $offset = ( $comment_page - 1 ) * $comments_per_page;
  23.                 $total_pages = (int)( get_comments_number() / $comments_per_page );
  24.                 echo "page: " . $comment_page . "\n";
  25.                 echo "per page: " . $comments_per_page . "\n";
  26.                 echo "post offset: " . $offset . "\n";
  27.                 echo "total pages: " . $total_pages . "\n";
  28.                 $args = array(
  29.                     'post_id' => get_the_id()
  30.                     , 'number' => $comments_per_page
  31.                     , 'offset' => $offset);
  32.                 $comments = get_comments( $args );
  33.                 $comment;
  34.                 foreach( $comments as $comment ) :
  35.                     $com_uid = $comment->user_id;
  36.                     $com_time_since = human_time_diff( get_comment_date( 'U', $comment->comment_ID ), get_the_time('U') );
  37.                     $com_author_avater_element = get_avatar( $com_uid );
  38.                     $com_author = $comment->comment_author;
  39.                     $com_author_url = $comment->comment_author_url;
  40.                     $com_content = $comment->comment_content;
  41.                     ?>
  42.                         <a name="comment-<?php echo $comment->comment_ID ?>"></a>
  43.                         <li class="list-group-item">
  44.                             <div class="row">
  45.                                 <div class="col-md-2 profile-thumb">
  46.                                     <a  href="<?php echo $com_author_url; ?>">
  47.                                         <?php echo $com_author_avater_element; ?>
  48.                                     </a>
  49.                                 </div>
  50.                                 <div class="col-md-10">
  51.                                     <h4>
  52.                                         <a href="<?php echo $com_author_url; ?>"><?php echo $com_author; ?></a>
  53.                                     </h4>
  54.                                     <p><?php echo $com_content; ?></p>
  55.                                     <span class="date"><i class="fa fa-clock-o"></i> <?php echo $com_time_since; ?></span>
  56.                                 </div>
  57.                             </div>
  58.                         </li>
  59.         <?php
  60.                 endforeach;
  61.             endif;
  62.                 ?>
  63.         <?php
  64.             if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
  65.                 <ul class="pagination">
  66.                     <?php
  67.                         $commentpage_url = "#respond";
  68.                         if ( $comment_page > 1 ){
  69.                             echo '<li>';
  70.                             $commentpage_url = get_permalink()
  71.                                 . "comment-page-"
  72.                                 . ($comment_page - 1)
  73.                                 . "/#comments";
  74.                         }
  75.                         else{
  76.                             echo '<li class="disabled">';
  77.                         } ?>
  78.                         <a href="<?php echo $commentpage_url; ?>">&laquo; Newer Comments</a>
  79.                     </li>
  80.                     <?php
  81.                         $commentpage_url = "#comments";
  82.                         if( $comment_page <= $total_pages ){
  83.                             echo '<li>';
  84.                             $commentpage_url = get_permalink()
  85.                                 . "comment-page-"
  86.                                 . ($comment_page + 1)
  87.                                 . "/#comments";
  88.                         }
  89.                         else {
  90.                             echo '<li class="disabled">';
  91.                         } ?>
  92.                         <a href="<?php echo $commentpage_url; ?>">Older Comments &raquo;</a>
  93.                        
  94.                     </li>
  95.                 </ul>
  96.         <?php
  97.             endif;?>
  98.        
  99.        
  100.         <!-- Comment Form -->
  101.         <a name="respond"></a>
  102.         <?php wbs\get_comment_form(); ?>
  103.         <!-- End Comment Form -->
  104.  
  105.     </ul>
  106.    
  107. </div>
  108. <!-- End Comments -->
  109.  
  110.  
  111. ////////////////////////////////////////////
  112. ////////////////////////////////////////////
  113. ////////////////////////////////////////////
  114.  
  115. functions.php (partial)
  116.  
  117. <?php
  118.  
  119. //other code stuffs (non related)
  120.  
  121. add_filter( 'comment_form_fields', 'wbs\move_comment_field' );
  122. function move_comment_field( $fields ) {
  123.     $comment_field = $fields['comment'];
  124.     unset( $fields['comment'] );
  125.     $fields['comment'] = $comment_field;
  126.     return $fields;
  127. }
  128.  
  129. add_filter('comment_form_defaults', 'wbs\set_comment_form_defaults');
  130. function set_comment_form_defaults() {
  131.     $commenter = wp_get_current_commenter();
  132.     $req = get_option( 'require_name_email' );
  133.     $aria_req = ( $req ? " aria-required='true'" : '' );
  134.  
  135.     $row_margin_bottom_20 = '<div class="row margin-bottom-20">' . "\n";
  136.     $col_md_7 = '<div class="col-md-7 col-md-offset-0">' . "\n";
  137.     $col_md_11 = '<div class="col-md-11 col-md-offset-0">' . "\n";
  138.     $text_input = '<input class="form-control" type="text" ';
  139.     $comment_input = '<textarea id="comment" name="comment" aria-required="true" class="form-control" rows="8" type="text"></textarea>';
  140.     $end_div = "</div>\n";
  141.     //$args fields
  142.  
  143.     $author = "<label>Name" . ( $req ? "<span>*</span>" : '' ) . "</label>\n"
  144.         . $row_margin_bottom_20 . $col_md_7
  145.         . $text_input . $aria_req
  146.         . 'name="author" value="' . esc_attr( $commenter['comment_author'] ) . '">' ."\n"
  147.         . $end_div . $end_div;
  148.  
  149.     $email = "<label>Email" . ( $req ? "<span>*</span>" : '' ) . "</label>\n"
  150.         . $row_margin_bottom_20 . $col_md_7
  151.         . $text_input . $aria_req
  152.         . 'name="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '">' ."\n"
  153.         . $end_div . $end_div;
  154.  
  155.     $url = "<label>Website</label>\n"
  156.         . $row_margin_bottom_20 . $col_md_7
  157.         . $text_input . $aria_req
  158.         . 'name="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '">' ."\n"
  159.         . $end_div . $end_div;
  160.  
  161.     $fields = apply_filters( 'comment_form_default_fields', array( 'author' => $author, 'email' => $email, 'url' => $url ) );
  162.  
  163.     $comment_field = "<label>Message</label>"
  164.         . $row_margin_bottom_20 . $col_md_11
  165.         . $comment_input . $end_div . $end_div;
  166.     $must_log_in;
  167.     $logged_in_as;
  168.  
  169.     $comment_notes_before = '<div class="row margin-top-20">' . "\n"
  170.         . '<div class="col-md-12">' . "\n"
  171.         . '<div class="pull-left">' . "\n"
  172.         . '<h3>Leave a Comment</h3>' . "\n"
  173.         . $end_div . $end_div . $end_div;
  174.  
  175.     $comment_notes_after = '';
  176.  
  177.     $id_submit = 'submit';
  178.     $class_submit = 'btn btn-primary';
  179.     $label_submit = 'Send Message';
  180.  
  181.     $title_reply = '';
  182.     $title_reply_to = '';
  183.     $title_reply_before = '';
  184.     $title_reply_after = '';
  185.    
  186.     $cancel_reply_before = '';
  187.     $cancel_reply_after = '';
  188.     $cancel_reply_link = '';
  189.    
  190.     $args = array(
  191.         'fields' => $fields
  192.         , 'comment_field' => $comment_field
  193.         , 'comment_notes_before' => $comment_notes_before
  194.         , 'id_submit' => $id_submit
  195.         , 'class_submit' => $class_submit
  196.         , 'label_submit' => $label_submit
  197.         , 'comment_notes_after' => $comment_notes_after
  198.  
  199.         , 'title_reply' => $title_reply
  200.         , 'title_reply_to' => $title_reply_to
  201.         , 'title_reply_before' => $title_reply_before
  202.         , 'title_reply_after' => $title_reply_after
  203.        
  204.         , 'cancel_reply_link' => $cancel_reply_link
  205.         , 'cancel_reply_before' => $cancel_reply_before
  206.         , 'cancel_reply_after' => $cancel_reply_after
  207.         );
  208.  
  209.     return $args;
  210. }
  211.  
  212. function get_comment_form() {
  213.     echo '<li class="list-group-item">' . "\n"
  214.         . '<div class="blog-comment-form">' . "\n";
  215.     comment_form();
  216.     echo "</div>\n</li>\n";
  217. }
  218.  
  219. ?>
Add Comment
Please, Sign In to add comment