ID ); } // don't show comments if pw-protected if ( post_password_required( $post_id ) ) { return false; } // if comments are not open for the post, return false if ( ! comments_open( $post_id ) ) {return false;} // if there are comments, this will contain text for the comments section title $comments_title = ''; // if there are comments, this will contain them $the_comments = ''; // if there are more comments than the pagination setting, this will contain them $comments_pagination = ''; // get the comment count for this post $comments_count = wp_count_comments( $post_id ); $comments_approved = absint( $comments_count->approved ); // are there comments approved for this post? if( !empty ( $comments_approved ) ) { $comments_title = anchorage_comments_title( $post_id ); $the_comments = anchorage_get_post_comments( $post_id ); $comments_pagination = anchorage_comments_pagination( $post_id ); } // start the output echo "
$comments_title
$the_comments $comments_pagination"; // There does not seem to be a way to return instead of echo. comment_form( array( 'title_reply' => ''.esc_html__( 'Leave a Comment', 'anchorage' ).'', 'comment_notes_before' => '', 'comment_notes_after' => '', ), $post_id ); echo "
"; } } /** * Returns the comments pagination for a post * * @param int $post_id The id of the post we're grabbing from * @return string The comments pagination for a post */ if(!function_exists('anchorage_comments_pagination')){ function anchorage_comments_pagination($post_id=''){ // determine which post we're grabbing from $post_id = absint( $post_id ); if(empty($post_id)) { global $post; $post_id = absint( $post->ID ); } // does this blog break comments into pages? $page_comments = get_option( 'page_comments' ); if(empty ( $page_comments ) ) { return false; } // how many comments per page? $comments_per_page = get_option( 'comments_per_page' ); // get the comment count for this post $comments_count = wp_count_comments( $post_id ); $comments_approved = absint( $comments_count->approved ); // are there more comments than can fit on one page? if so, show pagination if( $comments_approved <= $comments_per_page ) { return false; } // the link for newer comments $next = ''; if ( get_next_comments_link() ) { $next_text = "".esc_html__( 'Older Comments', 'anchorage' ); $next = "".get_next_comments_link( $next_text ).""; } $prev=''; if ( get_previous_comments_link() ) { $prev_text = esc_html__( 'Newer Comments', 'anchorage' ).""; $prev = "".get_previous_comments_link( $prev_text ).""; } // wrap the comments pagination $out = " "; return $out; } } /** * Returns the comments title for a post * * @param int $post_id The id of the post we're grabbing from * @return string The comments title for a post */ if(!function_exists('anchorage_comments_title')){ function anchorage_comments_title( $post_id='' ){ // determine which post we're grabbing from $post_id = absint( $post_id ); if(empty($post_id)) { global $post; $post_id = absint( $post->ID ); } // create a title for the comments section depending on how many comments there are $out = sprintf( _nx( 'One comment on “%2$s”', '%1$s comments on “%2$s”', get_comments_number( $post_id ), 'comments title', 'anchorage' ), number_format_i18n( get_comments_number( $post_id ) ), '' . get_the_title( $post_id ) . '' ); // wrap the comments title $out = '

'.$out.'

'; return $out; } } /** * Returns the comments for a post * * @param int $post_id The id of the post we're grabbing from * @return string The comments for a post */ if(!function_exists('anchorage_get_post_comments')){ function anchorage_get_post_comments( $post_id='' ){ // determine which post we're grabbing from $post_id = absint( $post_id ); if(empty($post_id)) { global $post; $post_id = absint( $post->ID ); } //Gather an array of comment objects for a specific page/post $comments = get_comments( array( 'post_id' => $post_id, 'status' => 'approve' ) ); // format the comments $out = wp_list_comments( array( 'style' => 'div', 'short_ping' => true, 'avatar_size' => 150, 'echo' => false, 'callback' => 'anchorage_comment', ), $comments ); // wrap the comments return "
".$out."
"; } } function anchorage_comment( $comment, $args, $depth ) { $GLOBALS['comment'] = $comment; $ping = ""; $comment_type = get_comment_type(); if( $comment_type != 'comment' ) { $ping = ''.esc_html( "$comment_type: " ).''; } ?>
id="comment-">
'.get_comment_author_link().''; ?>
comment_approved == '0' ) { ?>

'Respond ', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>