function comments_evolved_get_wordpress_count() { global $post, $comments, $wp_query, $comments_by_type, $id; $get_comments = get_comments('post_id=' . $id); $comments_by_type =& separate_comments($get_comments); return count($comments_by_type['comment']); }
function comment_count($count) { global $id; $get_comments = get_comments('post_id=' . $id); $comments_by_type =& separate_comments($get_comments); return count($comments_by_type['comment']); }
/** * */ function miss_comment_tab() { global $post; $get_comments = get_comments('post_id=' . $post->ID); $separate_comments = separate_comments($get_comments); $comments_by_type =& $separate_comments; ?> <div class="blog_tabs_container"> <ul class="blog_tabs"> <li><a href="#" class="current"><?php printf(_n('%1$s Comment', '%1$s Comments', count($comments_by_type['comment']), MISS_TEXTDOMAIN), number_format_i18n(count($comments_by_type['comment']))); ?> </a></li> <li><a href="#" class=""><?php printf(_n('%1$s Trackback', '%1$s Trackback', count($comments_by_type['pings']), MISS_TEXTDOMAIN), number_format_i18n(count($comments_by_type['pings']))); ?> </a></li> <div class="clearboth"></div> </ul><!-- .blog_tabs --> <div class="blog_tabs_content"> <ol class="commentlist"> <?php wp_list_comments(array('type' => 'comment', 'callback' => 'miss_comments_callback')); ?> </ol> <?php if (get_option('page_comments')) { ?> <div class="comment-navigation paged-navigation"> <?php paginate_comments_links(miss_portfolio_comment_url($nav = true)); ?> </div><!-- .comment-navigation --> <?php } ?> </div><!-- .blog_tabs_content --> <div class="blog_tabs_content"> <ol class="commentlist trackbacks_pingbacks"> <!-- <?php trackback_url(); ?> --> <?php wp_list_comments(array('type' => 'pings', 'callback' => 'miss_pings_callback')); ?> </ol> </div><!-- .blog_tabs_content --> </div><!-- .blog_tabs_container --> <?php }
function blankslate_comments_number($count) { if (!is_admin()) { global $id; $comments_by_type =& separate_comments(get_comments('status=approve&post_id=' . $id)); return count($comments_by_type['comment']); } else { return $count; } }
/** * Filter 'get_comments_number' * * Filter 'get_comments_number' to display correct * number of comments (count only comments, not * trackbacks/pingbacks) * * Chip Bennett Contribution */ function responsive_comment_count($count) { if (!is_admin()) { global $id; $comments = get_comments('status=approve&post_id=' . $id); $comments_by_type = separate_comments($comments); return count($comments_by_type['comment']); } else { return $count; } }
function comment_count($count) { if (!is_admin()) { global $id; $get_comments = get_comments('post_id=' . $id); $comments_by_type =& separate_comments($get_comments); return count($comments_by_type['comment']); } else { return $count; } }
function blankslate_comments_number($count) { if (!is_admin()) { global $id; $comments_by_type =& separate_comments(get_comments('status=approve&post_id=' . $id)); return count($comments_by_type['comment']); } else { return $count; } // Add to the admin_init hook of your theme functions.php file // Add tag metabox to page add_meta_box('tagsdiv-post_tag', __('Page Tags'), 'post_tags_meta_box', 'page', 'side', 'low'); register_taxonomy_for_object_type('post_tag', 'page'); // Add category metabox to page add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'page', 'side', 'core'); register_taxonomy_for_object_type('category', 'page'); register_taxonomy_for_object_type('post_tag', 'page'); register_taxonomy_for_object_type('category', 'page'); }
function comment_count($commentcount) { global $id; $_comments = get_comments('status=approve&post_id=' . $id); $comments_by_type =& separate_comments($_comments); return count($comments_by_type['comment']); }
next_comments_link(__('Newer Comments', APP_TD) . ' »', 0); ?> </div> <div class="clr"></div> </div><!-- /navigation --> <div class="clr"></div> <?php appthemes_before_blog_pings(); ?> <?php $carray = separate_comments($comments); // get the comments array to check for pings ?> <?php if (!empty($carray['pings'])) { // pings include pingbacks & trackbacks ?> <h2 class="dotted" id="pings"><?php _e('Trackbacks/Pingbacks', APP_TD); ?> </h2> <ol class="pinglist">
/** * function thesis_list_comments() * * List comments — Warning: Here be dragons. * * @param string|array $args Formatting options * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments * @since 1.5 * @usedby ../../comments.php * @uses Thesis_Comment */ function thesis_list_comments() { global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; $in_comment_loop = true; $comment_alt = $comment_thread_alt = 0; $comment_depth = 1; $r = array('walker' => null, 'max_depth' => '', 'type' => 'comment', 'page' => '', 'per_page' => '', 'reverse_top_level' => null, 'reverse_children' => ''); // Get our comments. $wp_query->comments_by_type =& separate_comments($wp_query->comments); $_comments = $wp_query->comments_by_type['comment']; // Are we paginating? if (get_option('page_comments')) { $r['per_page'] = get_query_var('comments_per_page'); } if (empty($r['per_page'])) { $r['per_page'] = 0; $r['page'] = 0; } // How deep does our comments hole go? if (get_option('thread_comments')) { $r['max_depth'] = get_option('thread_comments_depth'); } else { $r['max_depth'] = -1; } // Determine page number of comments. if (empty($overridden_cpage)) { $r['page'] = get_query_var('cpage'); } else { $threaded = -1 == $r['max_depth'] ? false : true; $r['page'] = 'newest' == get_option('default_comments_page') ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; set_query_var('cpage', $r['page']); } // Validate our page number. $r['page'] = intval($r['page']); if (0 == $r['page'] && 0 != $r['per_page']) { $r['page'] = 1; } // Which order should comments be displayed in? $r['reverse_top_level'] = 'desc' == get_option('comment_order') ? TRUE : FALSE; // Convert array into handy variables. extract($r, EXTR_SKIP); // Insantiate comments class. if (empty($walker)) { $walker = new Thesis_Comment(); } $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); $wp_query->max_num_comment_pages = $walker->max_pages; $in_comment_loop = false; }
/** * Replicates the core comments_template function, but uses the API * to fetch the comments and includes more filters. * * Loads the comment template specified in $file. * * Will not display the comments template if not on single post or page, or if * the post does not have comments. * * Uses the WordPress database object to query for the comments. The comments * are passed through the 'comments_array' filter hook with the list of comments * and the post ID respectively. * * The $file path is passed through a filter hook called, 'comments_template' * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path * first and if it fails it will require the default comment template from the * default theme. If either does not exist, then the WordPress process will be * halted. It is advised for that reason, that the default theme is not deleted. * * @since 1.5.0 * @global array $comment List of comment objects for the current post * @uses $wpdb * @uses $post * @uses $withcomments Will not try to get the comments if the post has none. * * @see comments_template() * * @param string $file Optional, default '/comments.php'. The file to load * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false. * @return null Returns null if no comments appear */ function bbl_comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /** * Comment author information fetched from the comment cookies. * * @uses wp_get_current_commenter() */ $commenter = wp_get_current_commenter(); /** * The name of the current comment author escaped for use in attributes. */ $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() /** * The email address of the current comment author escaped for use in attributes. */ $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() /** * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); $query = new Bbl_Comment_Query(); $args = array('order' => 'ASC', 'post_id' => $post->ID, 'status' => 'approve', 'status' => 'approve'); if ($user_ID) { $args['unapproved_user_id'] = $user_ID; } else { if (!empty($comment_author)) { $args['unapproved_author'] = wp_specialchars_decode($comment_author, ENT_QUOTES); $args['unapproved_author_email'] = $comment_author_email; } } $args = apply_filters('comments_template_args', $args); $comments = $query->query($args); // keep $comments for legacy's sake $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if ('' == get_query_var('cpage') && get_option('page_comments')) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } if (!defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE) { define('COMMENTS_TEMPLATE', true); } $include = apply_filters('comments_template', trailingslashit(get_stylesheet_directory()) . sanitize_file_name($file)); if (file_exists($include)) { require $include; } elseif (file_exists(trailingslashit(get_template_directory()) . sanitize_file_name($file))) { require trailingslashit(get_template_directory()) . sanitize_file_name($file); } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }
private function get_comments_list_template($comments, $post, $comments_count = null) { global $wp_query; // we store unmodified wp_query as the same object is used again later $original = clone $wp_query; // Fakes have_comments() that uses $wp_query->current_comment + 1 < $wp_query->comment_count if (!$comments_count) { $comments_count = count($comments); } if ($comments_count == 0) { $wp_query->current_comment = $comments_count; } $wp_query->comment_count = $comments_count; // Fakes comments_number() $post->comment_count = $comments_count; $this->add_overridden_comments_count_filter($comments_count); // Fakes wp_list_comments() $wp_query->comments = $comments; // Fakes $comments_by_type $c_by_type = separate_comments($comments); $wp_query->comments_by_type = $c_by_type; $comments_by_type = $wp_query->comments_by_type; // Hack for bad-written themes, which rely on globals instead of functions $GLOBALS['comments'] =& $comments; $GLOBALS['comment_count'] =& $comments_count; // Prints the template buffered ob_start(); include TEMPLATEPATH . '/comments.php'; $comments_template = ob_get_clean(); unset($GLOBALS['comments']); unset($GLOBALS['comment_count']); remove_filter('get_comments_number', 'overload_comments_number'); $wp_query = clone $original; return $comments_template; }
/** * List comments * * Used in the comments.php template to list comments for a particular post * * @since 2.7.0 * @uses Walker_Comment * * @param string|array $args Formatting options * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments */ function wp_list_comments($args = array(), $comments = null) { global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; $in_comment_loop = true; $comment_alt = $comment_thread_alt = 0; $comment_depth = 1; $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => ''); $r = wp_parse_args($args, $defaults); // Figure out what comments we'll be looping through ($_comments) if (null !== $comments) { $comments = (array) $comments; if (empty($comments)) { return; } if ('all' != $r['type']) { $comments_by_type =& separate_comments($comments); if (empty($comments_by_type[$r['type']])) { return; } $_comments = $comments_by_type[$r['type']]; } else { $_comments = $comments; } } else { if (empty($wp_query->comments)) { return; } if ('all' != $r['type']) { if (empty($wp_query->comments_by_type)) { $wp_query->comments_by_type =& separate_comments($wp_query->comments); } if (empty($wp_query->comments_by_type[$r['type']])) { return; } $_comments = $wp_query->comments_by_type[$r['type']]; } else { $_comments = $wp_query->comments; } } if ('' === $r['per_page'] && get_option('page_comments')) { $r['per_page'] = get_query_var('comments_per_page'); } if (empty($r['per_page'])) { $r['per_page'] = 0; $r['page'] = 0; } if ('' === $r['max_depth']) { if (get_option('thread_comments')) { $r['max_depth'] = get_option('thread_comments_depth'); } else { $r['max_depth'] = -1; } } if ('' === $r['page']) { if (empty($overridden_cpage)) { $r['page'] = get_query_var('cpage'); } else { $threaded = -1 == $r['max_depth'] ? false : true; $r['page'] = 'newest' == get_option('default_comments_page') ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; set_query_var('cpage', $r['page']); } } // Validation check $r['page'] = intval($r['page']); if (0 == $r['page'] && 0 != $r['per_page']) { $r['page'] = 1; } if (null === $r['reverse_top_level']) { $r['reverse_top_level'] = 'desc' == get_option('comment_order') ? TRUE : FALSE; } extract($r, EXTR_SKIP); if (empty($walker)) { $walker = new Walker_Comment(); } $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); $wp_query->max_num_comment_pages = $walker->max_pages; $in_comment_loop = false; }
* * Lists comments and calls the comment form. * * @package deTube * @subpackage Template * @since deTube 1.0 */ ?> <?php /* If there are no comments are given and comments/pings are closed and viewing a page, return. */ if (!have_comments() && !comments_open() && !pings_open() && is_page()) { return; } global $wp_query, $cpage; $comments_by_type =& separate_comments($wp_query->comments); $display_pings = false; // set to true if you want to display trackbacks/pingbakcs $cpage = $cpage > 1 ? $cpage : 1; ?> <?php dp_comment_form(array('comment_notes_after' => '')); ?> <?php if (!empty($comments_by_type['comment'])) { ?> <div id="comments"> <div class="section-header"><h2 class="section-title" id="comments-title"><?php comments_number(__('No Comments', 'dp'), __('1 Comment', 'dp'), __('% Comments', 'dp'));
/** * Gets the comments seperated by type * * @return array */ function hannover_get_comments_by_type() { global $wp_query, $post; $comment_args = array('order' => 'ASC', 'orderby' => 'comment_date_gmt', 'status' => 'approve', 'post_id' => $post->ID); $comments = get_comments($comment_args); $wp_query->comments_by_type = separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; return $comments_by_type; }
/** * Gets comments * @return array of WpLatteCommentEntity entities */ protected function getComments() { // copy&paste from comments_template() function global $wp_query, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; //if (!(is_single() || is_page())) // return; $req = get_option('require_name_email'); $commenter = wp_get_current_commenter(); $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies() $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies() $comment_author_url = esc_url($commenter['comment_author_url']); if ($user_ID) { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments}\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tcomment_post_ID = %d AND (comment_approved = '1' OR (user_id = %d AND comment_approved = '0'))\r\n\t\t\t\tORDER BY\r\n\t\t\t\t\tcomment_date_gmt", $this->id, $user_ID)); } elseif (empty($comment_author)) { $comments = get_comments(array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC')); } else { $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->comments}\r\n\t\t\tWHERE\r\n\t\t\t\tcomment_post_ID = %d AND (comment_approved = '1' OR (comment_author = %s AND comment_author_email = %s AND comment_approved = '0'))\r\n\t\t\tORDER BY\r\n\t\t\t\tcomment_date_gmt", $post->ID, wp_specialchars_decode($comment_author, ENT_QUOTES), $comment_author_email)); } $wp_query->comments = apply_filters('comments_array', $comments, $post->ID); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); update_comment_cache($wp_query->comments); $separate_comments = false; // $separate_comments Optional, whether to separate the comments by comment type. Default is false. if ($separate_comments) { $wp_query->comments_by_type =& separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } $overridden_cpage = FALSE; if (get_query_var('cpage') == '' && get_option('page_comments')) { set_query_var('cpage', get_option('default_comments_page') == 'newest' ? get_comment_pages_count() : 1); $overridden_cpage = TRUE; } // end of copy&paste code wp_list_comments(array('callback' => 'WpLattePostEntity::createCommentEntity', 'walker' => new WpLatteCommentWalker())); $this->comments = self::$commentEntities; self::$commentEntities = array(); // unset return $this->comments; }
function peacock_comments_number($count) { if (!is_admin()) { global $id; $comments = get_comments(array('status' => 'approve', 'post_id' => $id)); $comments_by_type = separate_comments($comments); return count($comments_by_type['comment']); } else { return $count; } }
function et_comment_count($count, $post_id) { $is_doing_ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false; if (!is_admin() || $is_doing_ajax) { global $id; $post_id = $post_id ? $post_id : $id; $get_comments = get_comments(array('post_id' => $post_id, 'status' => 'approve')); $comments_by_type = separate_comments($get_comments); return count($comments_by_type['comment']); } else { return $count; } }
public function html($args = array()) { global $thesis, $wp_query; extract($args = is_array($args) ? $args : array()); $tab = str_repeat("\t", $depth = !empty($depth) ? $depth : 0); if (empty($wp_query->comments_by_type)) { // separate the comments and put them in wp_query if they aren't there already $wp_query->comments_by_type =& separate_comments($wp_query->comments); } foreach ($wp_query->comments as $a) { if ($a->comment_type == 'pingback' || $a->comment_type == 'trackback') { $b[] = $a; } } if (empty($b)) { return; } $hook = trim($thesis->api->esc(!empty($this->options['hook']) ? $this->options['hook'] : $this->_id)); do_action("hook_before_{$hook}"); echo "{$tab}<ul id=\"trackback_list\">\n"; foreach ($b as $t) { $GLOBALS['comment'] = $t; echo "{$tab}\t<li>"; $this->rotator(array_merge($args, array('depth' => $depth + 1, 't' => $t))); echo "</li>\n"; } echo "{$tab}</ul>\n"; do_action("hook_after_{$hook}"); }
function arjuna_get_trackbacks_count() { global $id; $comments = get_comments('status=approve&post_id=' . $id); $comments_by_type = separate_comments($comments); return count($comments_by_type['pings']); }
function shiword_comment_count($count) { if (!is_admin()) { global $id; $comments_by_type =& separate_comments(get_comments('status=approve&post_id=' . $id)); $count = count($comments_by_type['comment']); } return $count; }
/** * Count comments. */ function padd_theme_hook_count_comments($count) { if (!is_admin()) { global $id; $comments_by_type =& separate_comments(get_comments('status=approve&post_id=' . $id)); return count($comments_by_type['comment']); } else { return $count; } }
/** * Template for displaying comments */ // Exit if accessed directly if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) { exit; } // Check if post password is required if (post_password_required()) { return; } if (have_comments()) { global $comments_by_type; $get_comments = get_comments('status=approve&post_id=' . $id); $comments_by_type = separate_comments($get_comments); if (!empty($comments_by_type['comment'])) { ?> <div id="comments"> <div class="comments-list"> <h3><?php comments_number(__('No comments', 'ambase'), __('One comment', 'ambase'), __('% comments', 'ambase')); ?> </h3> <ul> <?php wp_list_comments('callback=ambase_custom_comments'); ?> </ul> </div> <?php
/** * List comments. * * Used in the comments.php template to list comments for a particular post. * * @since 2.7.0 * * @see WP_Query->comments * * @global WP_Query $wp_query * @global int $comment_alt * @global int $comment_depth * @global int $comment_thread_alt * @global bool $overridden_cpage * @global bool $in_comment_loop * * @param string|array $args { * Optional. Formatting options. * * @type object $walker Instance of a Walker class to list comments. Default null. * @type int $max_depth The maximum comments depth. Default empty. * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'. * @type string $callback Callback function to use. Default null. * @type string $end-callback Callback function to use at the end. Default null. * @type string $type Type of comments to list. * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'. * @type int $page Page ID to list comments for. Default empty. * @type int $per_page Number of comments to list per page. Default empty. * @type int $avatar_size Height and width dimensions of the avatar size. Default 32. * @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'. * @type bool $reverse_children Whether to reverse child comments in the list. Default null. * @type string $format How to format the comments list. * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'. * @type bool $short_ping Whether to output short pings. Default false. * @type bool $echo Whether to echo the output or return it. Default true. * } * @param array $comments Optional. Array of WP_Comment objects. */ function wp_list_comments($args = array(), $comments = null) { global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; $in_comment_loop = true; $comment_alt = $comment_thread_alt = 0; $comment_depth = 1; $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true); $r = wp_parse_args($args, $defaults); /** * Filter the arguments used in retrieving the comment list. * * @since 4.0.0 * * @see wp_list_comments() * * @param array $r An array of arguments for displaying comments. */ $r = apply_filters('wp_list_comments_args', $r); // Figure out what comments we'll be looping through ($_comments) if (null !== $comments) { $comments = (array) $comments; if (empty($comments)) { return; } if ('all' != $r['type']) { $comments_by_type = separate_comments($comments); if (empty($comments_by_type[$r['type']])) { return; } $_comments = $comments_by_type[$r['type']]; } else { $_comments = $comments; } } else { /* * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, * perform a separate comment query and allow Walker_Comment to paginate. */ if ($r['page'] || $r['per_page']) { $current_cpage = get_query_var('cpage'); if (!$current_cpage) { $current_cpage = 'newest' === get_option('default_comments_page') ? 1 : $wp_query->max_num_comment_pages; } $current_per_page = get_query_var('comments_per_page'); if ($r['page'] != $current_cpage || $r['per_page'] != $current_per_page) { $comments = get_comments(array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'all')); if ('all' != $r['type']) { $comments_by_type = separate_comments($comments); if (empty($comments_by_type[$r['type']])) { return; } $_comments = $comments_by_type[$r['type']]; } else { $_comments = $comments; } } // Otherwise, fall back on the comments from `$wp_query->comments`. } else { if (empty($wp_query->comments)) { return; } if ('all' != $r['type']) { if (empty($wp_query->comments_by_type)) { $wp_query->comments_by_type = separate_comments($wp_query->comments); } if (empty($wp_query->comments_by_type[$r['type']])) { return; } $_comments = $wp_query->comments_by_type[$r['type']]; } else { $_comments = $wp_query->comments; } if ($wp_query->max_num_comment_pages) { $default_comments_page = get_option('default_comments_page'); $cpage = get_query_var('cpage'); if ('newest' === $default_comments_page) { $r['cpage'] = $cpage; /* * When first page shows oldest comments, post permalink is the same as * the comment permalink. */ } elseif ($cpage == 1) { $r['cpage'] = ''; } else { $r['cpage'] = $cpage; } $r['page'] = 0; $r['per_page'] = 0; } } } if ('' === $r['per_page'] && get_option('page_comments')) { $r['per_page'] = get_query_var('comments_per_page'); } if (empty($r['per_page'])) { $r['per_page'] = 0; $r['page'] = 0; } if ('' === $r['max_depth']) { if (get_option('thread_comments')) { $r['max_depth'] = get_option('thread_comments_depth'); } else { $r['max_depth'] = -1; } } if ('' === $r['page']) { if (empty($overridden_cpage)) { $r['page'] = get_query_var('cpage'); } else { $threaded = -1 != $r['max_depth']; $r['page'] = 'newest' == get_option('default_comments_page') ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; set_query_var('cpage', $r['page']); } } // Validation check $r['page'] = intval($r['page']); if (0 == $r['page'] && 0 != $r['per_page']) { $r['page'] = 1; } if (null === $r['reverse_top_level']) { $r['reverse_top_level'] = 'desc' == get_option('comment_order'); } wp_queue_comments_for_comment_meta_lazyload($_comments); if (empty($r['walker'])) { $walker = new Walker_Comment(); } else { $walker = $r['walker']; } $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r); $in_comment_loop = false; if ($r['echo']) { echo $output; } else { return $output; } }
function et_comment_count($count) { if (!is_admin()) { global $id; $get_comments = get_comments(array('post_id' => $id, 'status' => 'approve')); $comments_by_type =& separate_comments($get_comments); return count($comments_by_type['comment']); } else { return $count; } }
?> <h2 class="comments-title"> <?php printf(esc_html(_nx('One Comment', '%1$s Comments', get_comments_number(), 'comments title', 'jkl')), number_format_i18n(get_comments_number())); ?> </h2> <ol class="comment-list"> <?php wp_list_comments(array('style' => 'ol', 'short_ping' => true, 'avatar_size' => '96', 'type' => 'comment')); ?> </ol><!-- .comment-list --> <?php $comments = get_comments('status=approve&type=pings&post_id=' . $post->ID); $comments = separate_comments($comments); if (0 < count($comments['pings'])) { ?> <ol class="pings-list"> <h5 class="pings-list-title"><?php esc_attr_e('Pings', 'jkl'); ?> </h5> <?php wp_list_comments(array('style' => 'ol', 'short_ping' => true, 'type' => 'pings')); ?> </ol><!-- .pings-list --> <?php }
/** * List comments. * * Used in the comments.php template to list comments for a particular post. * * @since 2.7.0 * * @see WP_Query->comments * * @global WP_Query $wp_query * @global int $comment_alt * @global int $comment_depth * @global int $comment_thread_alt * @global bool $overridden_cpage * @global bool $in_comment_loop * * @param string|array $args { * Optional. Formatting options. * * @type object $walker Instance of a Walker class to list comments. Default null. * @type int $max_depth The maximum comments depth. Default empty. * @type string $style The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'. * @type string $callback Callback function to use. Default null. * @type string $end -callback Callback function to use at the end. Default null. * @type string $type Type of comments to list. * Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'. * @type int $page Page ID to list comments for. Default empty. * @type int $per_page Number of comments to list per page. Default empty. * @type int $avatar_size Height and width dimensions of the avatar size. Default 32. * @type string $reverse_top_level Ordering of the listed comments. Default null. Accepts 'desc', 'asc'. * @type bool $reverse_children Whether to reverse child comments in the list. Default null. * @type string $format How to format the comments list. * Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'. * @type bool $short_ping Whether to output short pings. Default false. * @type bool $echo Whether to echo the output or return it. Default true. * } * @param array $comments Optional. Array of comment objects. */ function wp_list_comments($args = array(), $comments = null) { global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop; $in_comment_loop = true; $comment_alt = $comment_thread_alt = 0; $comment_depth = 1; $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '', 'format' => current_theme_supports('html5', 'comment-list') ? 'html5' : 'xhtml', 'short_ping' => false, 'echo' => true); $r = wp_parse_args($args, $defaults); /** * Filter the arguments used in retrieving the comment list. * * @since 4.0.0 * * @see wp_list_comments() * * @param array $r An array of arguments for displaying comments. */ $r = apply_filters('wp_list_comments_args', $r); // Figure out what comments we'll be looping through ($_comments) if (null !== $comments) { $comments = (array) $comments; if (empty($comments)) { return; } if ('all' != $r['type']) { $comments_by_type = separate_comments($comments); if (empty($comments_by_type[$r['type']])) { return; } $_comments = $comments_by_type[$r['type']]; } else { $_comments = $comments; } } else { if (empty($wp_query->comments)) { return; } if ('all' != $r['type']) { if (empty($wp_query->comments_by_type)) { $wp_query->comments_by_type = separate_comments($wp_query->comments); } if (empty($wp_query->comments_by_type[$r['type']])) { return; } $_comments = $wp_query->comments_by_type[$r['type']]; } else { $_comments = $wp_query->comments; } } if ('' === $r['per_page'] && get_option('page_comments')) { $r['per_page'] = get_query_var('comments_per_page'); } if (empty($r['per_page'])) { $r['per_page'] = 0; $r['page'] = 0; } if ('' === $r['max_depth']) { if (get_option('thread_comments')) { $r['max_depth'] = get_option('thread_comments_depth'); } else { $r['max_depth'] = -1; } } if ('' === $r['page']) { if (empty($overridden_cpage)) { $r['page'] = get_query_var('cpage'); } else { $threaded = -1 != $r['max_depth']; $r['page'] = 'newest' == get_option('default_comments_page') ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1; set_query_var('cpage', $r['page']); } } // Validation check $r['page'] = intval($r['page']); if (0 == $r['page'] && 0 != $r['per_page']) { $r['page'] = 1; } if (null === $r['reverse_top_level']) { $r['reverse_top_level'] = 'desc' == get_option('comment_order'); } if (empty($r['walker'])) { $walker = new Walker_Comment(); } else { $walker = $r['walker']; } $output = $walker->paged_walk($_comments, $r['max_depth'], $r['page'], $r['per_page'], $r); $wp_query->max_num_comment_pages = $walker->max_pages; $in_comment_loop = false; if ($r['echo']) { echo $output; } else { return $output; } }
function comment_count_special($post_id, $comment_type) { $the_post_comments = get_comments('post_id=' . $post_id); $comments_by_type =& separate_comments($the_post_comments); return count($comments_by_type[$comment_type]); }
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) { die('Please do not load this page directly. Thanks!'); } if (post_password_required()) { ?> <p class="nocomments"><?php _e('This post is password protected. Enter the password to view comments.', 'woothemes'); ?> </p> <?php return; } ?> <?php $comments_by_type =& separate_comments($comments); ?> <!-- You can start editing here. --> <?php if (have_comments()) { ?> <div id="comments"> <?php if (!empty($comments_by_type['comment'])) { ?> <h3><?php
function comments_template($file = '/comments.php', $separate_comments = false) { global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage; if (!(is_single() || is_page() || $withcomments) || empty($post)) { return; } if (empty($file)) { $file = '/comments.php'; } $req = get_option('require_name_email'); /* * Comment author information fetched from the comment cookies. */ $commenter = wp_get_current_commenter(); /* * The name of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author = $commenter['comment_author']; /* * The email address of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */ $comment_author_email = $commenter['comment_author_email']; /* * The url of the current comment author escaped for use in attributes. */ $comment_author_url = esc_url($commenter['comment_author_url']); $comment_args = array('orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve', 'post_id' => $post->ID, 'hierarchical' => 'threaded', 'no_found_rows' => false, 'update_comment_meta_cache' => false); if ($user_ID) { $comment_args['include_unapproved'] = array($user_ID); } elseif (!empty($comment_author_email)) { $comment_args['include_unapproved'] = array($comment_author_email); } $per_page = 0; if (get_option('page_comments')) { $per_page = (int) get_query_var('comments_per_page'); if (0 === $per_page) { $per_page = (int) get_option('comments_per_page'); } $comment_args['number'] = $per_page; $page = (int) get_query_var('cpage'); if ($page) { $comment_args['offset'] = ($page - 1) * $per_page; } elseif ('oldest' === get_option('default_comments_page')) { $comment_args['offset'] = 0; } else { // If fetching the first page of 'newest', we need a top-level comment count. $top_level_query = new WP_Comment_Query(); $top_level_count = $top_level_query->query(array('count' => true, 'orderby' => false, 'post_id' => $post->ID, 'parent' => 0)); $comment_args['offset'] = (ceil($top_level_count / $per_page) - 1) * $per_page; } } $comment_query = new WP_Comment_Query($comment_args); $_comments = $comment_query->comments; // Trees must be flattened before they're passed to the walker. $comments_flat = array(); foreach ($_comments as $_comment) { $comments_flat = array_merge($comments_flat, array($_comment), $_comment->get_children(array('format' => 'flat', 'status' => $comment_args['status'], 'orderby' => $comment_args['orderby']))); } $wp_query->comments = apply_filters('comments_array', $comments_flat, $post->ID); // Set up lazy-loading for comment metadata. add_action('get_comment_metadata', array($wp_query, 'lazyload_comment_meta'), 10, 2); $comments =& $wp_query->comments; $wp_query->comment_count = count($wp_query->comments); $wp_query->max_num_comment_pages = $comment_query->max_num_pages; if ($separate_comments) { $wp_query->comments_by_type = separate_comments($comments); $comments_by_type =& $wp_query->comments_by_type; } else { $wp_query->comments_by_type = array(); } $overridden_cpage = false; if ('' == get_query_var('cpage') && $wp_query->max_num_comment_pages > 1) { set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); $overridden_cpage = true; } if (!defined('COMMENTS_TEMPLATE')) { define('COMMENTS_TEMPLATE', true); } $theme_template = STYLESHEETPATH . $file; $include = apply_filters('comments_template', $theme_template); if (file_exists($include)) { require $include; } elseif (file_exists(TEMPLATEPATH . $file)) { require TEMPLATEPATH . $file; } else { // Backward compat code will be removed in a future release require ABSPATH . WPINC . '/theme-compat/comments.php'; } }