当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Query::is_singular方法代码示例

本文整理汇总了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;
 }
开发者ID:kanei,项目名称:vantuch.cz,代码行数:16,代码来源:class.frame-nonce-preview.php

示例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;
     }
 }
开发者ID:RJHanson292,项目名称:WP-e-Commerce,代码行数:27,代码来源:router.php

示例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;
}
开发者ID:hadywisam,项目名称:WordPress,代码行数:36,代码来源:comment-functions.php

示例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;
 }
开发者ID:TheBillPleaseZA,项目名称:archiveless,代码行数:16,代码来源:archiveless.php

示例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;
 }
开发者ID:sedici,项目名称:wpmu-istec,代码行数:51,代码来源:class_upfront_entity_resolver.php


注:本文中的WP_Query::is_singular方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。