本文整理汇总了PHP中WP_Comment_Query::query方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Comment_Query::query方法的具体用法?PHP WP_Comment_Query::query怎么用?PHP WP_Comment_Query::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Comment_Query
的用法示例。
在下文中一共展示了WP_Comment_Query::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enp_popular_comments_save
function enp_popular_comments_save($btn_slug, $post_types, $args)
{
// all comments by btn slug (combines pages, posts, etc. anywhere the button is shown)
$comment_args = array('fields' => 'ids', 'status' => 'approve', 'number' => 20);
$args = array_merge($comment_args, $args);
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
$popular_comments = enp_build_popular_array($btn_slug, $comments, 'comment');
update_option('enp_button_popular_' . $btn_slug . '_comments', $popular_comments);
// Loop through all the passed post_types and
// save all comments by post type
// ex: enp_button_popular_respect_page_comments
foreach ($post_types as $key => $value) {
// check if the button type is active
if ($value === '1' && $key !== 'comment') {
// build the arguments
$post_type_args = array('post_type' => $key);
$post_type_args = array_merge($args, $post_type_args);
// generate the query
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($post_type_args);
// build the array of popular ids and counts
$popular_comments = enp_build_popular_array($btn_slug, $comments, 'comment');
// save the array
update_option('enp_button_popular_' . $btn_slug . '_' . $key . '_comments', $popular_comments);
}
}
}
示例2: get_items
/**
* Get a list of reactions.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items($request)
{
$prepared_args = array('post__in' => $request['post'], 'type' => 'reaction');
/**
* Filter arguments, before passing to WP_Comment_Query, when querying reactions via the REST API.
*
* @see https://developer.wordpress.org/reference/classes/wp_comment_query/
*
* @param array $prepared_args Array of arguments for WP_Comment_Query.
* @param WP_REST_Request $request The current request.
*/
$prepared_args = apply_filters('rest_reaction_query', $prepared_args, $request);
$query = new WP_Comment_Query();
$query_result = $query->query($prepared_args);
$reactions_count = array();
foreach ($query_result as $reaction) {
if (empty($reactions_count[$reaction->comment_content])) {
$reactions_count[$reaction->comment_content] = array('count' => 0, 'post_id' => $reaction->comment_post_ID);
}
$reactions_count[$reaction->comment_content]++;
}
$reactions = array();
foreach ($reactions_count as $emoji => $data) {
$reaction = array('emoji' => $emoji, 'count' => $data['count'], 'post_id' => $data['post_id']);
$data = $this->prepare_item_for_response($reaction, $request);
$reactions[] = $this->prepare_response_for_collection($data);
}
$total_reactions = (int) $query->found_comments;
$reaction_groups = count($reactions);
$response = rest_ensure_response($reactions);
$response->header('X-WP-Total', $total_reactions);
$response->header('X-WP-TotalGroups', $reaction_groups);
return $response;
}
示例3: cases_display_todo_comments
function cases_display_todo_comments()
{
if (!is_singular('cases')) {
return;
}
if (!shortcode_exists('cp_todo_comments')) {
return;
}
global $post;
$args = array('post_id' => $post->ID, 'meta_query' => array(array('key' => 'cp_control', 'value' => 'yes')), 'meta_key' => 'cp_control_order', 'orderby' => 'meta_value_num', 'order' => 'ASC');
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
if (empty($comments)) {
return;
}
?>
<section id="case_todo_comments_wrapper" class="cases-box">
<header class="cases-box-header">
<h1>Комментарии на контроле</h1>
<hr>
</header>
<article class="cases-box-content">
<?php
echo do_shortcode('[cp_todo_comments]');
?>
</article>
</section>
<?php
}
示例4: get_items
/**
* Get a list of comments.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items($request)
{
$prepared_args = array('comment__in' => $request['include'], 'comment__not_in' => $request['exclude'], 'number' => $request['per_page'], 'post_id' => $request['post'] ? $request['post'] : '', 'parent' => isset($request['parent']) ? $request['parent'] : '', 'search' => $request['search'], 'offset' => $request['offset'], 'orderby' => $this->normalize_query_param($request['orderby']), 'order' => $request['order'], 'status' => 'approve', 'type' => 'comment', 'no_found_rows' => false);
if (empty($request['offset'])) {
$prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1);
}
if (current_user_can('edit_posts')) {
$protected_args = array('user_id' => $request['author'] ? $request['author'] : '', 'status' => $request['status'], 'type' => isset($request['type']) ? $request['type'] : '', 'author_email' => isset($request['author_email']) ? $request['author_email'] : '', 'karma' => isset($request['karma']) ? $request['karma'] : '', 'post_author' => isset($request['post_author']) ? $request['post_author'] : '', 'post_name' => isset($request['post_slug']) ? $request['post_slug'] : '', 'post_parent' => isset($request['post_parent']) ? $request['post_parent'] : '', 'post_status' => isset($request['post_status']) ? $request['post_status'] : '', 'post_type' => isset($request['post_type']) ? $request['post_type'] : '');
$prepared_args = array_merge($prepared_args, $protected_args);
}
/**
* Filter arguments, before passing to WP_Comment_Query, when querying comments via the REST API.
*
* @see https://developer.wordpress.org/reference/classes/wp_comment_query/
*
* @param array $prepared_args Array of arguments for WP_Comment_Query.
* @param WP_REST_Request $request The current request.
*/
$prepared_args = apply_filters('rest_comment_query', $prepared_args, $request);
$query = new WP_Comment_Query();
$query_result = $query->query($prepared_args);
$comments = array();
foreach ($query_result as $comment) {
$post = get_post($comment->comment_post_ID);
if (!$this->check_read_post_permission($post) || !$this->check_read_permission($comment)) {
continue;
}
$data = $this->prepare_item_for_response($comment, $request);
$comments[] = $this->prepare_response_for_collection($data);
}
$total_comments = (int) $query->found_comments;
$max_pages = (int) $query->max_num_pages;
if ($total_comments < 1) {
// Out-of-bounds, run the query again without LIMIT for total count
unset($prepared_args['number']);
unset($prepared_args['offset']);
$query = new WP_Comment_Query();
$prepared_args['count'] = true;
$total_comments = $query->query($prepared_args);
$max_pages = ceil($total_comments / $request['per_page']);
}
$response = rest_ensure_response($comments);
$response->header('X-WP-Total', $total_comments);
$response->header('X-WP-TotalPages', $max_pages);
$base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/comments'));
if ($request['page'] > 1) {
$prev_page = $request['page'] - 1;
if ($prev_page > $max_pages) {
$prev_page = $max_pages;
}
$prev_link = add_query_arg('page', $prev_page, $base);
$response->link_header('prev', $prev_link);
}
if ($max_pages > $request['page']) {
$next_page = $request['page'] + 1;
$next_link = add_query_arg('page', $next_page, $base);
$response->link_header('next', $next_link);
}
return $response;
}
示例5: find
public function find($args = array(), &$found = null)
{
//add filter for before/after handling, hopefully more complex date querying
//will exist by wp3.7
if (isset($args['before']) || isset($args['after'])) {
add_filter('comments_clauses', array(__CLASS__, '_filter_comments_clauses_handleDateRange'), 10, 2);
}
//setup paging
if (empty($args['per_page'])) {
$number = get_option('comments_per_page');
if ($number < 1) {
$number = \Voce\Thermal\v1\MAX_COMMENTS_PER_PAGE;
}
}
if (isset($args['offset'])) {
$offset = $args['offset'];
} elseif (isset($args['paged'])) {
$offset = (absint($args['paged']) - 1) * $number;
} else {
$offset = 0;
}
//normalize search arg
if (isset($args['s'])) {
$args['search'] = $args['s'];
unset($args['s']);
}
//allow 'in' arg
if (!empty($args['in'])) {
add_filter('comments_clauses', array(__CLASS__, '_filter_comments_clauses_handleInArg'), 10, 2);
}
//status handling
if (empty($args['status'])) {
$args['status'] = 'approve';
}
//make sure count isn't set to true
$args['count'] = false;
$wp_comments = new \WP_Comment_Query();
$comments = $wp_comments->query($args);
if (!empty($args['include_found'])) {
$args['count'] = true;
//@todo - counts don't cache in core
$found = $wp_comments->query($args);
}
return $comments;
}
示例6: hackgov_get_comments
/**
* Get comment for all post by user
* @param string $user_id [description]
* @return [type] [description]
*/
function hackgov_get_comments($user_id = '')
{
if (empty($user_id)) {
$user_id = get_current_user_id();
}
$args = array('post_author__in' => $user_id, 'post_status' => 'publish');
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
return $comments;
}
示例7: getTrackingObject
public static function getTrackingObject()
{
$hash = md5(network_site_url() . '-' . $_SERVER['REMOTE_ADDR']);
global $blog_id, $wpdb;
$pts = array();
foreach (get_post_types(array('public' => true)) as $pt) {
$count = wp_count_posts($pt);
$pts[$pt] = $count->publish;
}
$comments_count = wp_count_comments();
$theme_data = wp_get_theme();
$theme = array('version' => $theme_data->Version, 'name' => $theme_data->Name, 'author' => $theme_data->Author, 'template' => $theme_data->Template);
if (!function_exists('get_plugin_data')) {
require_once ABSPATH . 'wp-admin/includes/admin.php';
}
$plugins = array();
foreach (get_option('active_plugins', array()) as $plugin_path) {
$plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
$slug = str_replace('/' . basename($plugin_path), '', $plugin_path);
$plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']);
}
if (is_multisite()) {
foreach (get_option('active_sitewide_plugins', array()) as $plugin_path) {
$plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
$slug = str_replace('/' . basename($plugin_path), '', $plugin_path);
$plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']);
}
}
$version = explode('.', PHP_VERSION);
$version = array('major' => $version[0], 'minor' => $version[0] . '.' . $version[1], 'release' => PHP_VERSION);
$user_query = new WP_User_Query(array('blog_id' => $blog_id, 'count_total' => true));
$comments_query = new WP_Comment_Query();
$data = array('_id' => $hash, 'localhost' => $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ? 1 : 0, 'php' => $version, 'site' => array('hash' => $hash, 'version' => get_bloginfo('version'), 'multisite' => is_multisite(), 'users' => $user_query->get_total(), 'lang' => get_locale(), 'wp_debug' => defined('WP_DEBUG') ? WP_DEBUG ? true : false : false, 'memory' => WP_MEMORY_LIMIT), 'pts' => $pts, 'comments' => array('total' => $comments_count->total_comments, 'approved' => $comments_count->approved, 'spam' => $comments_count->spam, 'pings' => $comments_query->query(array('count' => true, 'type' => 'pingback'))), 'options' => apply_filters('redux/tracking/options', array()), 'theme' => $theme, 'redux' => array('mode' => ReduxFramework::$_is_plugin ? 'plugin' : 'theme', 'version' => ReduxFramework::$_version, 'demo_mode' => get_option('ReduxFrameworkPlugin')), 'developer' => apply_filters('redux/tracking/developer', array()), 'plugins' => $plugins);
$parts = explode(' ', $_SERVER['SERVER_SOFTWARE']);
$software = array();
foreach ($parts as $part) {
if ($part[0] == "(") {
continue;
}
if (strpos($part, '/') !== false) {
$chunk = explode("/", $part);
$software[strtolower($chunk[0])] = $chunk[1];
}
}
$software['full'] = $_SERVER['SERVER_SOFTWARE'];
$data['environment'] = $software;
if (function_exists('mysql_get_server_info')) {
$data['environment']['mysql'] = mysql_get_server_info();
}
if (empty($data['developer'])) {
unset($data['developer']);
}
return $data;
}
示例8: widget
/** @see WP_Widget::widget -- do not rename this */
function widget($args, $instance)
{
extract($args);
//Our variables from the widget settings.
$title = apply_filters('widget_title', $instance['title']);
$width = $instance['width'];
$number = $instance['number'];
echo '<div class="' . $width . '">
<div class="dash-widget">' . $before_widget;
// Display the widget title
if ($title) {
echo $before_title . $title . $after_title;
}
$unit_comments = vibe_get_option('unit_comments');
if (isset($unit_comments) && is_numeric($unit_comments)) {
$link = get_permalink($unit_comments);
} else {
$link = '#';
}
echo '<div id="vibe-tabs-notes_discussion" class="tabs tabbable">
<a href="' . $link . '" class="view_all_notes">' . __('SEE ALL', 'wplms-dashboard') . '</a>
<ul class="nav nav-tabs clearfix">
<li><a href="#tab-notes" data-toggle="tab">' . __('My Notes', 'wplms-dashboard') . '</a></li>
<li><a href="#tab-discussion" data-toggle="tab">' . __('My Discussions', 'wplms-dashboard') . '</a></li>
</ul><div class="tab-content">';
echo '<div id="tab-notes" class="tab-pane">';
$user_id = get_current_user_id();
$args = apply_filters('wplms_notes_dicussion_dashboard_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'note', 'user_id' => $user_id));
echo '<div id="notes_query">' . json_encode($args) . '</div>
<div id="notes_discussions">';
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
// Comment Loop
$vibe_notes_discussions = new vibe_notes_discussions();
$vibe_notes_discussions->comments_loop($comments);
echo '</div></div>';
echo '<div id="tab-discussion" class="tab-pane">';
$args = apply_filters('wplms_notes_dicussion_dashboard_args', array('number' => $number, 'post_status' => 'publish', 'post_type' => 'unit', 'status' => 'approve', 'type' => 'public', 'user_id' => $user_id));
echo '<div id="notes_query">' . json_encode($args) . '</div>
<div id="notes_discussions">';
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
// Comment Loop
$vibe_notes_discussions = new vibe_notes_discussions();
$vibe_notes_discussions->comments_loop($comments);
echo '</div></div>';
echo '</div></div>';
echo $after_widget . '
</div>
</div>';
}
示例9: foreach
function custom_recent_comments($amount = 5, $avatar_size = 35)
{
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query(array('number' => $amount));
$comm = '';
if ($comments) {
foreach ($comments as $comment) {
$comm .= '<li><div class="recent-avatar">' . get_avatar($comment->comment_author_email, $avatar_size);
$comm .= '</div><div class="recent-text"><p><a class="recent-author" href="' . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">';
$comm .= get_comment_author($comment->comment_ID) . '</a> la:<br /> ';
$comm .= '<a href="' . get_permalink($comment->comment_post_ID) . '">' . get_the_title($comment->comment_post_ID) . '</a></p></div></li>';
}
} else {
$comm .= 'No comments.';
}
echo $comm;
}
示例10: widget
/**
* Outputs the content of the widget.
*
* @param array args The array of form elements
* @param array instance The current instance of the widget
*/
public function widget($args, $instance)
{
$cache = wp_cache_get('featured_comments_widget', 'widget');
if (!is_array($cache)) {
$cache = array();
}
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
if (isset($cache[$args['widget_id']])) {
echo $cache[$args['widget_id']];
return;
}
$title = apply_filters('widget_title', $instance['title']);
$output = '';
if (empty($instance['number']) || $instance['number'] < 1) {
$intance['number'] = 5;
}
$query_args = apply_filters('featured_comments_query', array('number' => $instance['number'], 'status' => 'approve', 'post_status' => 'publish', 'meta_query' => array(array('key' => 'featured', 'value' => '1'))));
$query = new WP_Comment_Query();
$comments = $query->query($query_args);
if ($comments) {
$output = $args['before_widget'];
if ($title) {
$output .= $args['before_title'] . $title . $args['after_title'];
}
$output .= '<ul id="featured-comments">';
if ($comments) {
foreach ((array) $comments as $comment) {
$output .= '<li class="featured-comments">';
$output .= sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link($comment->comment_ID), '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">' . get_the_title($comment->comment_post_ID) . '</a>');
$output .= '</li>';
}
}
$output .= '</ul>';
}
$output .= $args['after_widget'];
echo $output;
$cache[$args['widget_id']] = $output;
wp_cache_set('featured_comments_widget', $cache, 'widget');
}
示例11: get_items
/**
* Get a list of comments.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_Error|WP_REST_Response
*/
public function get_items($request)
{
$prepared_args = $this->prepare_items_query($request);
$query = new WP_Comment_Query();
$query_result = $query->query($prepared_args);
$comments = array();
foreach ($query_result as $comment) {
$post = get_post($comment->comment_post_ID);
if (!$this->check_read_post_permission($post) || !$this->check_read_permission($comment)) {
continue;
}
$data = $this->prepare_item_for_response($comment, $request);
$comments[] = $this->prepare_response_for_collection($data);
}
$response = rest_ensure_response($comments);
unset($prepared_args['number']);
unset($prepared_args['offset']);
$query = new WP_Comment_Query();
$prepared_args['count'] = true;
$total_comments = $query->query($prepared_args);
$response->header('X-WP-Total', (int) $total_comments);
$max_pages = ceil($total_comments / $request['per_page']);
$response->header('X-WP-TotalPages', (int) $max_pages);
$base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/comments'));
if ($request['page'] > 1) {
$prev_page = $request['page'] - 1;
if ($prev_page > $max_pages) {
$prev_page = $max_pages;
}
$prev_link = add_query_arg('page', $prev_page, $base);
$response->link_header('prev', $prev_link);
}
if ($max_pages > $request['page']) {
$next_page = $request['page'] + 1;
$next_link = add_query_arg('page', $next_page, $base);
$response->link_header('next', $next_link);
}
return $response;
}
示例12: get_page_of_comment
/**
* Calculate what page number a comment will appear on for comment paging.
*
* @since 2.7.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $comment_ID Comment ID.
* @param array $args {
* Array of optional arguments.
* @type string $type Limit paginated comments to those matching a given type. Accepts 'comment',
* 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
* Default is 'all'.
* @type int $per_page Per-page count to use when calculating pagination. Defaults to the value of the
* 'comments_per_page' option.
* @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
* `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
* } *
* @return int|null Comment page number or null on error.
*/
function get_page_of_comment($comment_ID, $args = array())
{
global $wpdb;
$page = null;
if (!($comment = get_comment($comment_ID))) {
return;
}
$defaults = array('type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '');
$args = wp_parse_args($args, $defaults);
$original_args = $args;
// Order of precedence: 1. `$args['per_page']`, 2. 'comments_per_page' query_var, 3. 'comments_per_page' option.
if (get_option('page_comments')) {
if ('' === $args['per_page']) {
$args['per_page'] = get_query_var('comments_per_page');
}
if ('' === $args['per_page']) {
$args['per_page'] = get_option('comments_per_page');
}
}
if (empty($args['per_page'])) {
$args['per_page'] = 0;
$args['page'] = 0;
}
if ($args['per_page'] < 1) {
$page = 1;
}
if (null === $page) {
if ('' === $args['max_depth']) {
if (get_option('thread_comments')) {
$args['max_depth'] = get_option('thread_comments_depth');
} else {
$args['max_depth'] = -1;
}
}
// Find this comment's top level parent if threading is enabled
if ($args['max_depth'] > 1 && 0 != $comment->comment_parent) {
return get_page_of_comment($comment->comment_parent, $args);
}
$comment_args = array('type' => $args['type'], 'post_id' => $comment->comment_post_ID, 'fields' => 'ids', 'count' => true, 'status' => 'approve', 'parent' => 0, 'date_query' => array(array('column' => "{$wpdb->comments}.comment_date_gmt", 'before' => $comment->comment_date_gmt)));
$comment_query = new WP_Comment_Query();
$older_comment_count = $comment_query->query($comment_args);
// No older comments? Then it's page #1.
if (0 == $older_comment_count) {
$page = 1;
// Divide comments older than this one by comments per page to get this comment's page number
} else {
$page = ceil(($older_comment_count + 1) / $args['per_page']);
}
}
/**
* Filters the calculated page on which a comment appears.
*
* @since 4.4.0
*
* @param int $page Comment page.
* @param array $args {
* Arguments used to calculate pagination. These include arguments auto-detected by the function,
* based on query vars, system settings, etc. For pristine arguments passed to the function,
* see `$original_args`.
*
* @type string $type Type of comments to count.
* @type int $page Calculated current page.
* @type int $per_page Calculated number of comments per page.
* @type int $max_depth Maximum comment threading depth allowed.
* }
* @param array $original_args {
* Array of arguments passed to the function. Some or all of these may not be set.
*
* @type string $type Type of comments to count.
* @type int $page Current comment page.
* @type int $per_page Number of comments per page.
* @type int $max_depth Maximum comment threading depth allowed.
* }
*/
return apply_filters('get_page_of_comment', (int) $page, $args, $original_args);
}
示例13: isset
function render_comments_table($limit)
{
global $current_user, $wpdb;
$pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1;
$offset = ($pagenum - 1) * $limit;
$args = array('number' => $limit, 'offset' => $offset, 'post_author' => $current_user->ID, 'post_type' => 'download', 'status' => 'approve', 'meta_query' => array(array('key' => 'fes-already-processed', 'compare' => 'NOT EXISTS')));
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
if (count($comments) == 0) {
echo '<tr><td colspan="4">' . __('No Comments Found', 'edd_fes') . '</td></tr>';
}
foreach ($comments as $comment) {
$this->render_comments_table_row($comment);
}
$args = array('post_author' => $current_user->ID, 'post_type' => 'download', 'status' => 'approve', 'author__not_in' => array($current_user->ID), 'meta_query' => array(array('key' => 'fes-already-processed', 'compare' => 'NOT EXISTS')));
$comments_query = new WP_Comment_Query();
$comments = $comments_query->query($args);
if (count($comments) > 0) {
$pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1;
$num_of_pages = ceil(count($comments) / $limit);
$page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'prev_text' => __('«', 'aag'), 'next_text' => __('»', 'aag'), 'total' => $num_of_pages, 'current' => $pagenum));
if ($page_links) {
echo '<div class="fes-pagination">' . $page_links . '</div>';
}
}
}
示例14: intval
//.........这里部分代码省略.........
<?php
echo comments_number(__('No Comment', 'wp-tab-widget'), __('One Comment', 'wp-tab-widget'), '<span class="comments-number">%</span> ' . __('Comments', 'wp-tab-widget'));
?>
<?php
}
?>
</div> <!--end .entry-meta-->
<?php
}
?>
<?php
if ($show_excerpt == 1) {
?>
<div class="wpt_excerpt">
<p><?php
echo $this->excerpt($excerpt_length);
?>
</p>
</div>
<?php
}
?>
<div class="clear"></div>
</li>
<?php
$post_num++;
}
wp_reset_query();
?>
</ul>
<div class="clear"></div>
<?php
if ($allow_pagination) {
?>
<?php
$this->tab_pagination($page, $last_page);
?>
<?php
}
?>
<?php
break;
/* ---------- Recent Posts ---------- */
/* ---------- Recent Posts ---------- */
case "recent":
?>
<ul>
<?php
$recent = new WP_Query('posts_per_page=' . $post_num . '&orderby=post_date&order=desc&post_status=publish&paged=' . $page);
$last_page = $recent->max_num_pages;
while ($recent->have_posts()) {
$recent->the_post();
?>
<li>
示例15: comments_template
/**
* Load 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.
*
* Will not try to get the comments if the post has none.
*
* @since 1.5.0
*
* @global WP_Query $wp_query
* @global WP_Post $post
* @global wpdb $wpdb
* @global int $id
* @global WP_Comment $comment
* @global string $user_login
* @global int $user_ID
* @global string $user_identity
* @global bool $overridden_cpage
* @global bool $withcomments
*
* @param string $file Optional. The file to load. Default '/comments.php'.
* @param bool $separate_comments Optional. Whether to separate the comments by comment type.
* Default false.
*/
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, 'no_found_rows' => false, 'update_comment_meta_cache' => false);
if (get_option('thread_comments')) {
$comment_args['hierarchical'] = 'threaded';
} else {
$comment_args['hierarchical'] = 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_args = array('count' => true, 'orderby' => false, 'post_id' => $post->ID, 'status' => 'approve');
if ($comment_args['hierarchical']) {
$top_level_args['parent'] = 0;
}
if (isset($comment_args['include_unapproved'])) {
$top_level_args['include_unapproved'] = $comment_args['include_unapproved'];
}
$top_level_count = $top_level_query->query($top_level_args);
$comment_args['offset'] = (ceil($top_level_count / $per_page) - 1) * $per_page;
}
}
//.........这里部分代码省略.........