Number of WordPress article comments called outside the loop

WordPress one five hundred and thirty-three Reading mode

Number of WordPress article comments called outside the loop

 function add_comment_count_to_posts() { global $wpdb, $post; $id = $post->ID;//  Article ID $comment_count = $wpdb->get_var( "SELECT comment_count FROM $wpdb->posts WHERE post_status = 'publish' AND ID = $id" );//  Get article comments $comment_status = $wpdb->get_var( "SELECT comment_status FROM $wpdb->posts WHERE ID = $id" );//  Whether the article has opened comments $html = '<div class="comment-popup">'; $html .= '< span>'; $count = ''; if( $comment_status == 'open' ) { $count = $comment_count; } else { $count='Comment closed'; } $html .= $ count . '</span></div>'; return $html; }

Get the latest comment date of an article:

 $comment_args = array( 'post_id'   => get_the_ID(), 'number'    => 1, ); $latest_comment = get_comments($comment_args); echo $latest_comment[0]->comment_date;
 Number of WordPress article comments called outside the loop

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
    •  Arlo Navigation
      Arlo Navigation one

      Take away :razz:

     anonymous

    Comment

    Anonymous netizens
     :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

    Drag the slider to complete validation