/** * Retrieve a list of comments. * * The comment list can be for the blog as a whole or for an individual post. * * The list of comment arguments are: * - 'status' * - 'orderby' * - 'comment_date_gmt' * - 'order' * - 'number' * - 'offset' * - 'post_id' * * - 'taxonomy' : taxonomy name, defaults to 'category' * - 'term_ids' : comma-separated list of term ids or array of term ids * - 'terms' : comma-separated list of terms (e.g. category names) or array of category names * * @param mixed $args Optional. Array or string of options to override defaults. * @return array List of comments. */ public static function get_comments($args = '') { $query = new Decent_Comment(); return $query->query($args); }
/** * Renders comments. * * These options defined in Decent_Comments_Renderer::$defaults are supported. * @see Decent_Comments_Renderer::$defaults * * @param array $options determines what settings are used to render which comments * @return rendered comments * @uses Decent_Comments_Renderer::get_comment() */ static function get_comments($options = array()) { // output $output = ''; extract(self::$defaults); // comment selection options if (isset($options['number'])) { $number = intval($options['number']); } if (isset($options['order'])) { $order = 'ASC' == strtoupper($options['order']) ? 'ASC' : 'DESC'; } if (isset($options['orderby'])) { $orderby = $options['orderby']; } if (isset($options['post_id']) && $options['post_id'] !== null) { if ("{current}" == $options['post_id'] || "[current]" == $options['post_id']) { $post_id = get_the_ID(); } else { if ($post = get_post($options['post_id'])) { $post_id = $post->ID; } } } // Any chosen terms? - Needs taxonomy to be given as well. if (isset($options['terms'])) { $terms = $options['terms']; } // Any term ids given? - Needs taxonomy to be given as well. if (isset($options['term_ids'])) { $term_ids = $options['term_ids']; } // What taxonomy? - {current} will void $terms and $term_ids above and // replace with those related to current post if any. $taxonomy = !empty($options['taxonomy']) ? $options['taxonomy'] : self::$defaults['taxonomy']; if (isset($options['terms']) && !empty($taxonomy)) { // If the {current} option is used, get the current post's terms // and use their ids to look for comments on posts that are // related to the same terms. if ("{current}" == $options['terms'] || "[current]" == $options['terms']) { // limit to term ids $terms = null; $foo = get_the_ID(); $term_ids = array(); // build term ids if ($current_terms = get_the_terms(get_the_ID(), $taxonomy)) { foreach ($current_terms as $term) { $term_ids[] = $term->term_id; } } } } // basic options: number, sort, comments must be approved $comment_args = array('number' => $number, 'order' => $order, 'orderby' => $orderby, 'status' => 'approve'); // comments for a specific post if (isset($post_id)) { $comment_args['post_id'] = $post_id; } // comments related to taxonomies & terms if (!empty($taxonomy)) { $comment_args['taxonomy'] = $taxonomy; } if (!empty($terms)) { $comment_args['terms'] = $terms; } if (!empty($term_ids)) { $comment_args['term_ids'] = $term_ids; } require_once dirname(__FILE__) . '/class-decent-comment.php'; $comments = Decent_Comment::get_comments($comment_args); if (!empty($comments)) { // display options if (isset($options['avatar_size'])) { $avatar_size = intval($options['avatar_size']); } if (isset($options['excerpt'])) { $excerpt = $options['excerpt'] !== false; } if (isset($options['max_excerpt_words'])) { $max_excerpt_words = intval($options['max_excerpt_words']); } if (isset($options['ellipsis'])) { $ellipsis = $options['ellipsis']; } if (isset($options['show_author'])) { $show_author = $options['show_author'] !== false; } if (isset($options['show_avatar'])) { $show_avatar = $options['show_avatar'] !== false; } if (isset($options['show_link'])) { $show_link = $options['show_link'] !== false; } if (isset($options['show_comment'])) { $show_comment = $options['show_comment'] !== false; } $output .= '<div class="decent-comments">'; $output .= '<ul>'; foreach ($comments as $comment) { $output .= '<li>'; $output .= '<div class="comment">'; if ($show_avatar) { $output .= '<span class="comment-avatar">'; $output .= '<a href="' . get_comment_author_url($comment->comment_ID) . '" rel="external">'; $output .= get_avatar($comment->comment_author_email); $output .= '</a>'; $output .= '</span>'; // .comment-avatar } $output .= '<div class="comment-details">'; if ($show_author) { $output .= '<span class="comment-author">'; $output .= get_comment_author_link($comment->comment_ID); $output .= '</span>'; // .comment-author } if ($show_link) { $output .= '<span class="comment-link">'; $output .= sprintf(_x(' on %s', 'comment-link', TD), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>'); $output .= '</span>'; // .comment-link } if ($show_comment) { $output .= '<span class="comment-' . ($excerpt ? "excerpt" : "body") . '">'; $output .= self::get_comment($comment, array("ellipsis" => $ellipsis, "excerpt" => $excerpt, "max_excerpt_words" => $max_excerpt_words)); $output .= '</span>'; // .comment-body or .comment-excerpt } $output .= '</div>'; $output .= '</div>'; // .comment $output .= '</li>'; } $output .= '</ul>'; $output .= '</div>'; // .decent-comments } return $output; }