Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //comments.php
- <!-- Comments -->
- <div class="blog-recent-comments panel panel-default margin-bottom-30">
- <a name="comments"></a>
- <div class="panel-heading">
- <h3>
- <a href="#respond">Reply</a> -
- <?php
- global $cpage;
- $comment_page = $cpage;
- if( $comment_page == '' ) $comment_page=1;
- echo comments_number(); ?>
- </h3>
- </div>
- <ul class="list-group">
- <?php
- if ( have_comments() ) :
- echo $cpage;
- $comments_per_page = get_option('comments_per_page');
- $offset = ( $comment_page - 1 ) * $comments_per_page;
- $total_pages = (int)( get_comments_number() / $comments_per_page );
- echo "page: " . $comment_page . "\n";
- echo "per page: " . $comments_per_page . "\n";
- echo "post offset: " . $offset . "\n";
- echo "total pages: " . $total_pages . "\n";
- $args = array(
- 'post_id' => get_the_id()
- , 'number' => $comments_per_page
- , 'offset' => $offset);
- $comments = get_comments( $args );
- $comment;
- foreach( $comments as $comment ) :
- $com_uid = $comment->user_id;
- $com_time_since = human_time_diff( get_comment_date( 'U', $comment->comment_ID ), get_the_time('U') );
- $com_author_avater_element = get_avatar( $com_uid );
- $com_author = $comment->comment_author;
- $com_author_url = $comment->comment_author_url;
- $com_content = $comment->comment_content;
- ?>
- <a name="comment-<?php echo $comment->comment_ID ?>"></a>
- <li class="list-group-item">
- <div class="row">
- <div class="col-md-2 profile-thumb">
- <a href="<?php echo $com_author_url; ?>">
- <?php echo $com_author_avater_element; ?>
- </a>
- </div>
- <div class="col-md-10">
- <h4>
- <a href="<?php echo $com_author_url; ?>"><?php echo $com_author; ?></a>
- </h4>
- <p><?php echo $com_content; ?></p>
- <span class="date"><i class="fa fa-clock-o"></i> <?php echo $com_time_since; ?></span>
- </div>
- </div>
- </li>
- <?php
- endforeach;
- endif;
- ?>
- <?php
- if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : ?>
- <ul class="pagination">
- <?php
- $commentpage_url = "#respond";
- if ( $comment_page > 1 ){
- echo '<li>';
- $commentpage_url = get_permalink()
- . "comment-page-"
- . ($comment_page - 1)
- . "/#comments";
- }
- else{
- echo '<li class="disabled">';
- } ?>
- <a href="<?php echo $commentpage_url; ?>">« Newer Comments</a>
- </li>
- <?php
- $commentpage_url = "#comments";
- if( $comment_page <= $total_pages ){
- echo '<li>';
- $commentpage_url = get_permalink()
- . "comment-page-"
- . ($comment_page + 1)
- . "/#comments";
- }
- else {
- echo '<li class="disabled">';
- } ?>
- <a href="<?php echo $commentpage_url; ?>">Older Comments »</a>
- </li>
- </ul>
- <?php
- endif;?>
- <!-- Comment Form -->
- <a name="respond"></a>
- <?php wbs\get_comment_form(); ?>
- <!-- End Comment Form -->
- </ul>
- </div>
- <!-- End Comments -->
- ////////////////////////////////////////////
- ////////////////////////////////////////////
- ////////////////////////////////////////////
- functions.php (partial)
- <?php
- //other code stuffs (non related)
- add_filter( 'comment_form_fields', 'wbs\move_comment_field' );
- function move_comment_field( $fields ) {
- $comment_field = $fields['comment'];
- unset( $fields['comment'] );
- $fields['comment'] = $comment_field;
- return $fields;
- }
- add_filter('comment_form_defaults', 'wbs\set_comment_form_defaults');
- function set_comment_form_defaults() {
- $commenter = wp_get_current_commenter();
- $req = get_option( 'require_name_email' );
- $aria_req = ( $req ? " aria-required='true'" : '' );
- $row_margin_bottom_20 = '<div class="row margin-bottom-20">' . "\n";
- $col_md_7 = '<div class="col-md-7 col-md-offset-0">' . "\n";
- $col_md_11 = '<div class="col-md-11 col-md-offset-0">' . "\n";
- $text_input = '<input class="form-control" type="text" ';
- $comment_input = '<textarea id="comment" name="comment" aria-required="true" class="form-control" rows="8" type="text"></textarea>';
- $end_div = "</div>\n";
- //$args fields
- $author = "<label>Name" . ( $req ? "<span>*</span>" : '' ) . "</label>\n"
- . $row_margin_bottom_20 . $col_md_7
- . $text_input . $aria_req
- . 'name="author" value="' . esc_attr( $commenter['comment_author'] ) . '">' ."\n"
- . $end_div . $end_div;
- $email = "<label>Email" . ( $req ? "<span>*</span>" : '' ) . "</label>\n"
- . $row_margin_bottom_20 . $col_md_7
- . $text_input . $aria_req
- . 'name="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '">' ."\n"
- . $end_div . $end_div;
- $url = "<label>Website</label>\n"
- . $row_margin_bottom_20 . $col_md_7
- . $text_input . $aria_req
- . 'name="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '">' ."\n"
- . $end_div . $end_div;
- $fields = apply_filters( 'comment_form_default_fields', array( 'author' => $author, 'email' => $email, 'url' => $url ) );
- $comment_field = "<label>Message</label>"
- . $row_margin_bottom_20 . $col_md_11
- . $comment_input . $end_div . $end_div;
- $must_log_in;
- $logged_in_as;
- $comment_notes_before = '<div class="row margin-top-20">' . "\n"
- . '<div class="col-md-12">' . "\n"
- . '<div class="pull-left">' . "\n"
- . '<h3>Leave a Comment</h3>' . "\n"
- . $end_div . $end_div . $end_div;
- $comment_notes_after = '';
- $id_submit = 'submit';
- $class_submit = 'btn btn-primary';
- $label_submit = 'Send Message';
- $title_reply = '';
- $title_reply_to = '';
- $title_reply_before = '';
- $title_reply_after = '';
- $cancel_reply_before = '';
- $cancel_reply_after = '';
- $cancel_reply_link = '';
- $args = array(
- 'fields' => $fields
- , 'comment_field' => $comment_field
- , 'comment_notes_before' => $comment_notes_before
- , 'id_submit' => $id_submit
- , 'class_submit' => $class_submit
- , 'label_submit' => $label_submit
- , 'comment_notes_after' => $comment_notes_after
- , 'title_reply' => $title_reply
- , 'title_reply_to' => $title_reply_to
- , 'title_reply_before' => $title_reply_before
- , 'title_reply_after' => $title_reply_after
- , 'cancel_reply_link' => $cancel_reply_link
- , 'cancel_reply_before' => $cancel_reply_before
- , 'cancel_reply_after' => $cancel_reply_after
- );
- return $args;
- }
- function get_comment_form() {
- echo '<li class="list-group-item">' . "\n"
- . '<div class="blog-comment-form">' . "\n";
- comment_form();
- echo "</div>\n</li>\n";
- }
- ?>
Add Comment
Please, Sign In to add comment