本文整理汇总了PHP中WP_Query::is_singular方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::is_singular方法的具体用法?PHP WP_Query::is_singular怎么用?PHP WP_Query::is_singular使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Query
的用法示例。
在下文中一共展示了WP_Query::is_singular方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: maybe_display_post
/**
* Conditionally add a hook on posts_results if this is the main query, a preview, and singular.
*
* @since 4.4.0
*
* @param WP_Query $query
*
* @return WP_Query
*/
public function maybe_display_post($query)
{
if ($query->is_main_query() && $query->is_preview() && $query->is_singular()) {
add_filter('posts_results', array($this, 'set_post_to_publish'), 10, 2);
}
return $query;
}
示例2: _action_prepare_front_page
/**
* In case the store is set as front page, fool WordPress into thinking
* this is a wpsc-product post type archive before the database is queried
* for posts.
*
* Action hook: 'pre_get_post'
*
* @since 0.1
* @access private
*
* @param WP_Query $q query object
*/
public function _action_prepare_front_page($q)
{
if (!$q->is_main_query()) {
return;
}
if ($q->is_singular() && 'wpsc-product' == $q->get('post_type')) {
add_filter('posts_where', array($this, '_prepare_single_product'), 10, 2);
}
if ($this->is_store_front_page()) {
$q->set('post_type', 'wpsc-product');
$q->wpsc_is_store_front_page = true;
$q->is_post_type_archive = true;
$q->is_archive = true;
}
}
示例3: _close_comments_for_old_posts
/**
* Close comments on old posts on the fly, without any extra DB queries. Hooked to the_posts.
*
* @access private
* @since 2.7.0
*
* @param WP_Post $posts Post data object.
* @param WP_Query $query Query object.
* @return array
*/
function _close_comments_for_old_posts($posts, $query)
{
if (empty($posts) || !$query->is_singular() || !get_option('close_comments_for_old_posts')) {
return $posts;
}
/**
* Filter the list of post types to automatically close comments for.
*
* @since 3.2.0
*
* @param array $post_types An array of registered post types. Default array with 'post'.
*/
$post_types = apply_filters('close_comments_for_post_types', array('post'));
if (!in_array($posts[0]->post_type, $post_types)) {
return $posts;
}
$days_old = (int) get_option('close_comments_days_old');
if (!$days_old) {
return $posts;
}
if (time() - strtotime($posts[0]->post_date_gmt) > $days_old * DAY_IN_SECONDS) {
$posts[0]->comment_status = 'closed';
$posts[0]->ping_status = 'closed';
}
return $posts;
}
示例4: posts_where
/**
* Hide archiveless posts on non-singular pages.
*
* @param string $where MySQL WHERE clause.
* @param WP_Query $query Current WP_Query object.
* @return string WHERE clause, potentially with 'archiveless' post status
* removed.
*/
public function posts_where($where, $query)
{
global $wpdb;
if ($query->is_main_query() && !$query->is_singular() && false !== strpos($where, " OR {$wpdb->posts}.post_status = '{$this->status}'")) {
$where = str_replace(" OR {$wpdb->posts}.post_status = '{$this->status}'", '', $where);
}
return $where;
}
示例5: ids_from_url
public static function ids_from_url($url)
{
global $wp;
$wp = new WP();
//We need to cheat telling WP we are not in admin area to parse the URL properly
$current_uri = $_SERVER['REQUEST_URI'];
$self = $_SERVER['PHP_SELF'];
$get = $_GET;
global $current_screen;
if ($current_screen) {
$stored_current_screen = $current_screen->id;
} else {
require_once ABSPATH . '/wp-admin/includes/screen.php';
$current_screen = WP_Screen::get('front');
}
$_SERVER['REQUEST_URI'] = $url;
$_SERVER['PHP_SELF'] = 'foo';
$urlParts = explode('?', $url);
if (count($urlParts) > 1) {
parse_str($urlParts[1], $_GET);
}
$wp->parse_request();
$query = new WP_Query($wp->query_vars);
$query->parse_query();
//Set the global post in case that no-one is set and we have a single query
global $post;
if (!$post && $query->have_posts() && $query->is_singular()) {
$post = $query->next_post();
setup_postdata($post);
}
//Make the query accessible to add it to the response
global $upfront_ajax_query;
$upfront_ajax_query = clone $query;
// Intercept /edit/(post|page)/id
$editor = Upfront_ContentEditor_VirtualPage::serve();
if ($editor->parse_page()) {
global $wp_query;
$query = $wp_query;
$post = $wp_query->next_post();
setup_postdata($post);
}
$_SERVER['REQUEST_URI'] = $current_uri;
$_SERVER['PHP_SELF'] = $self;
$_GET = $get;
if (isset($stored_current_screen)) {
//$current_screen = $current_screen::get($stored_current_screen);
$current_screen = call_user_func(array($current_screen, 'get', $stored_current_screen));
}
$cascade = self::get_entity_ids(self::get_entity_cascade($query));
return $cascade;
}