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


PHP WP_Query::is_single方法代码示例

本文整理汇总了PHP中WP_Query::is_single方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Query::is_single方法的具体用法?PHP WP_Query::is_single怎么用?PHP WP_Query::is_single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Query的用法示例。


在下文中一共展示了WP_Query::is_single方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _mangapress_comics_pre_get_posts

/**
 * Modify queries for Comics
 *
 * @global wpdb $wpdb WordPress DB oject
 * @param WP_Query $query
 */
function _mangapress_comics_pre_get_posts($query)
{
    global $wpdb;
    if ($query->get('post_type') !== MangaPress_Posts::POST_TYPE || is_admin()) {
        return;
    }
    $sql = "SELECT * FROM {$wpdb->term_taxonomy} WHERE taxonomy='" . MangaPress_Posts::TAX_SERIES . "'";
    $is_taxonomy = $wpdb->get_var($sql);
    if (!$is_taxonomy) {
        return;
    }
    add_filter('posts_join', 'mangapress_join');
    if ($query->is_single()) {
        add_filter('posts_fields', 'mangapress_select_fields');
    } else {
        add_filter('posts_distinct', 'mangapress_distinct_rows');
    }
}
开发者ID:jesgs,项目名称:mangapress,代码行数:24,代码来源:query.php

示例2: array

 /**
  * Get the fork's parent post, set up a query, and load correct template.
  *
  * Duplicates the functionality of /wp-includes/template-loader.php and includes
  * a lot of copypasta, but that's only to ensure that it follows the same logic.
  *
  */
 function choose_template()
 {
     $p = get_queried_object_id();
     if (get_post_type($p) !== 'fork') {
         return;
     }
     $pp = get_post($p)->post_parent;
     $parent = get_post($pp);
     if ($parent->post_type == 'page') {
         $query = array('page_id' => $pp);
     } else {
         $query = array('p' => $pp);
     }
     $t = new WP_Query($query);
     $template = false;
     if ($t->is_404() && ($template = get_404_template())) {
     } elseif ($t->is_search() && ($template = get_search_template())) {
     } elseif ($t->is_tax() && ($template = get_taxonomy_template())) {
     } elseif ($t->is_front_page() && ($template = get_front_page_template())) {
     } elseif ($t->is_home() && ($template = get_home_template())) {
     } elseif ($t->is_attachment() && ($template = get_attachment_template())) {
         remove_filter('the_content', 'prepend_attachment');
     } elseif ($t->is_single() && ($template = get_single_template())) {
     } elseif ($t->is_page && ($template = get_page_template())) {
     } elseif ($t->is_category() && ($template = get_category_template())) {
     } elseif ($t->is_tag() && ($template = get_tag_template())) {
     } elseif ($t->is_author() && ($template = get_author_template())) {
     } elseif ($t->is_date() && ($template = get_date_template())) {
     } elseif ($t->is_archive() && ($template = get_archive_template())) {
     } elseif ($t->is_comments_popup() && ($template = get_comments_popup_template())) {
     } elseif ($t->is_paged() && ($template = get_paged_template())) {
     } else {
         $template = get_index_template();
     }
     if ($template = apply_filters('template_include', $template)) {
         include $template;
     }
     return;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:46,代码来源:preview.php

示例3: query_navigation_headers

 /**
  * Send navigation-related headers for post collections
  *
  * @param WP_Query $query
  */
 public function query_navigation_headers($query)
 {
     $max_page = $query->max_num_pages;
     $paged = $query->get('paged');
     if (!$paged) {
         $paged = 1;
     }
     $nextpage = intval($paged) + 1;
     if (!$query->is_single()) {
         if ($paged > 1) {
             $request = remove_query_arg('page');
             $request = add_query_arg('page', $paged - 1, $request);
             $this->set_info('prev', $paged - 1);
         }
         if ($nextpage <= $max_page) {
             $request = remove_query_arg('page');
             $request = add_query_arg('page', $nextpage, $request);
             $this->set_info('next', $nextpage);
         }
     }
     $this->set_info('total', $query->found_posts);
     $this->set_info('total_page', $max_page);
     do_action('json_query_navigation_headers', $this, $query);
 }
开发者ID:Mushan3420,项目名称:BigApp-PHP7,代码行数:29,代码来源:class-wp-json-response.php

示例4: pre_get_posts

 /**
  * Add custom query modification to the pre_get_posts hook as necessary for PRO.
  *
  * @param WP_Query $query The current query object.
  *
  * @return WP_Query The modified query object.
  */
 public function pre_get_posts($query)
 {
     if ($query->is_single() && $query->get('eventDate')) {
         $this->set_post_id_for_recurring_event_query($query);
     }
     if (!empty($query->tribe_is_event_pro_query)) {
         switch ($query->query_vars['eventDisplay']) {
             case 'week':
                 $start_date = tribe_get_first_week_day($query->get('eventDate'));
                 $end_date = tribe_get_last_week_day($start_date);
                 // if the setting to hide weekends is true
                 if (tribe_get_option('week_view_hide_weekends', false) == true) {
                     $start_of_week = get_option('start_of_week');
                     // check if the week is set to start on a weekend day
                     // If so, start on the next weekday.
                     // 0 = Sunday, 6 = Saturday
                     if ($start_of_week == 0 || $start_of_week == 6) {
                         $start_date = date(Tribe__Events__Date_Utils::DBDATEFORMAT, strtotime($start_date . ' +1 Weekday'));
                     }
                     // If the week starts on saturday or friday
                     // sunday and/or saturday would be on the other end, so we need to end the previous weekday
                     // 5 = Friday, 6 = Saturday
                     if ($start_of_week == 5 || $start_of_week == 6) {
                         $end_date = date(Tribe__Events__Date_Utils::DBDATEFORMAT, strtotime($end_date . ' -1 Weekday'));
                     }
                 }
                 // if the setting to hide weekends is on
                 // need to filter the query
                 // need to only show 5 days on the week view
                 // if we're using an non-default hour range on week view
                 if (has_filter('tribe_events_week_get_hours')) {
                     $start_date .= ' ' . tribe_events_week_get_hours('first-hour');
                     $end_date .= ' ' . tribe_events_week_get_hours('last-hour');
                 }
                 $query->set('eventDate', $start_date);
                 $query->set('start_date', $start_date);
                 $query->set('end_date', $end_date);
                 $query->set('posts_per_page', -1);
                 // show ALL week posts
                 $query->set('hide_upcoming', false);
                 break;
             case 'photo':
                 $query->set('hide_upcoming', false);
                 break;
             case 'all':
                 new Tribe__Events__Pro__Recurrence__Event_Query($query);
                 break;
         }
         apply_filters('tribe_events_pro_pre_get_posts', $query);
     }
 }
开发者ID:TravisSperry,项目名称:mpa_website,代码行数:58,代码来源:Main.php

示例5: pre_get_posts

 /**
  * Add custom query modification to the pre_get_posts hook as necessary for PRO.
  *
  * @param WP_Query $query The current query object.
  * @return WP_Query The modified query object.
  * @author Timothy Wood
  * @since 3.0
  */
 public function pre_get_posts($query)
 {
     if ($query->is_single() && $query->get('eventDate')) {
         $this->set_post_id_for_recurring_event_query($query);
     }
     if (!empty($query->tribe_is_event_pro_query)) {
         switch ($query->query_vars['eventDisplay']) {
             case 'week':
                 $week = tribe_get_first_week_day($query->get('eventDate'));
                 $query->set('eventDate', $week);
                 $query->set('start_date', $week);
                 $query->set('end_date', tribe_get_last_week_day($week));
                 $query->set('posts_per_page', -1);
                 // show ALL week posts
                 $query->set('hide_upcoming', false);
                 break;
             case 'photo':
                 $query->set('hide_upcoming', false);
                 break;
             case 'all':
                 $slug = $query->get('name');
                 if (empty($slug)) {
                     break;
                     // we shouldn't be here
                 }
                 unset($query->query_vars['name']);
                 unset($query->query_vars['tribe_events']);
                 $all_ids = TribeEventsRecurrenceMeta::get_events_by_slug($slug);
                 if (empty($all_ids)) {
                     $query->set('p', -1);
                 } else {
                     $query->set('post__in', $all_ids);
                     $query->set('post_status', 'publish');
                 }
                 break;
         }
         apply_filters('tribe_events_pro_pre_get_posts', $query);
     }
 }
开发者ID:pellio11,项目名称:ns-select-project,代码行数:47,代码来源:events-calendar-pro.php

示例6: is_single_event_main_query

 protected function is_single_event_main_query(WP_Query $query)
 {
     return $query->is_main_query() && $query->is_single() && $query->get('post_type') === Tribe__Events__Main::POSTTYPE;
 }
开发者ID:TakenCdosG,项目名称:chefs,代码行数:4,代码来源:Filters.php

示例7: pre_get_posts

 /**
  * Add custom query modification to the pre_get_posts hook as necessary for PRO.
  *
  * @param WP_Query $query The current query object.
  *
  * @return WP_Query The modified query object.
  */
 public function pre_get_posts($query)
 {
     if ($query->is_single() && $query->get('eventDate')) {
         $this->set_post_id_for_recurring_event_query($query);
     }
     if (!empty($query->tribe_is_event_pro_query)) {
         switch ($query->query_vars['eventDisplay']) {
             case 'week':
                 $start_date = tribe_get_first_week_day($query->get('eventDate'));
                 $end_date = tribe_get_last_week_day($start_date);
                 // if the setting to hide weekends is true
                 if (tribe_get_option('week_view_hide_weekends', false) == true) {
                     $start_of_week = get_option('start_of_week');
                     // check if the week is set to start on a weekend day
                     // If so, start on the next weekday.
                     // 0 = Sunday, 6 = Saturday
                     if ($start_of_week == 0 || $start_of_week == 6) {
                         $start_date = date(Tribe__Events__Date_Utils::DBDATEFORMAT, strtotime($start_date . ' +1 Weekday'));
                     }
                     // If the week starts on saturday or friday
                     // sunday and/or saturday would be on the other end, so we need to end the previous weekday
                     // 5 = Friday, 6 = Saturday
                     if ($start_of_week == 5 || $start_of_week == 6) {
                         $end_date = date(Tribe__Events__Date_Utils::DBDATEFORMAT, strtotime($end_date . ' -1 Weekday'));
                     }
                 }
                 // if the setting to hide weekends is on
                 // need to filter the query
                 // need to only show 5 days on the week view
                 // if we're using an non-default hour range on week view
                 if (has_filter('tribe_events_week_get_hours')) {
                     $start_date .= ' ' . tribe_events_week_get_hours('first-hour');
                     $end_date .= ' ' . tribe_events_week_get_hours('last-hour');
                 }
                 $query->set('eventDate', $start_date);
                 $query->set('start_date', $start_date);
                 $query->set('end_date', $end_date);
                 $query->set('posts_per_page', -1);
                 // show ALL week posts
                 $query->set('hide_upcoming', false);
                 break;
             case 'photo':
                 $query->set('hide_upcoming', false);
                 break;
             case 'all':
                 $slug = $query->get('name');
                 if (empty($slug)) {
                     break;
                     // we shouldn't be here
                 }
                 unset($query->query_vars['name']);
                 unset($query->query_vars['tribe_events']);
                 $posts = get_posts(array('name' => $slug, 'post_type' => Tribe__Events__Main::POSTTYPE, 'post_status' => 'publish', 'numberposts' => 1));
                 $post = reset($posts);
                 if (empty($post)) {
                     $query->set('p', -1);
                 } else {
                     $query->set('post_parent', $post->ID);
                     $query->set('post_status', 'publish');
                     $query->set('posts_per_page', tribe_get_option('postsPerPage', 10));
                     $query->is_singular = false;
                 }
                 break;
         }
         apply_filters('tribe_events_pro_pre_get_posts', $query);
     }
 }
开发者ID:simple-beck,项目名称:project-gc,代码行数:74,代码来源:Main.php

示例8: _add_key_terms

 /**
  * Get the term keys for every term associated with a post.
  *
  * @since 1.0.0.
  *
  * @param  int      $post_id  Post ID.
  * @param  string   $taxonomy The taxonomy to look for associated terms.
  * @param  WP_Query $wp_query The current wp_query to investigate.
  * @return array              The term slug/taxonomy combos for the post.
  */
 private function _add_key_terms($post_id, $taxonomy, $wp_query)
 {
     $terms = array();
     $keys = array();
     $queried_object = get_queried_object();
     if ($wp_query->is_single()) {
         $terms = get_the_terms($post_id, $taxonomy);
     } else {
         if (isset($queried_object->slug) && isset($queried_object->taxonomy) && $taxonomy === $queried_object->taxonomy) {
             $terms[] = $queried_object;
         }
     }
     if (is_array($terms)) {
         foreach ($terms as $term) {
             if (isset($term->slug)) {
                 $keys[] = $taxonomy . '-' . $term->slug;
             }
         }
     }
     return $keys;
 }
开发者ID:KostasNi,项目名称:purgely,代码行数:31,代码来源:surrogate-key-collection.php

示例9: defineLookupOrder


//.........这里部分代码省略.........
         // taxonomy-[taxonomy]-[term-slug]
         // taxonomy-[taxonomy]
         // taxonomy-[post-type]
         // taxonomy
         // archive-[post-type]
         // [post-type]
         // archive
         $term = get_queried_object();
         if (!empty($term->slug)) {
             $result[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug;
             $result[] = 'taxonomy-' . $term->taxonomy;
         }
         if ($query_post_type) {
             $result[] = 'taxonomy-' . $query_post_type;
         }
         $result[] = 'taxonomy';
         if ($query_post_type) {
             $result[] = 'archive-' . $query_post_type;
             $result[] = $query_post_type;
         }
         $result[] = 'archive';
     } elseif ($wp_query->is_date()) {
         // date-[post-type]
         // date
         // archive-[post-type]
         // [post-type]
         // archive
         if ($query_post_type) {
             $result[] = 'date-' . $query_post_type;
         }
         $result[] = 'date';
         if ($query_post_type) {
             $result[] = 'archive-' . $query_post_type;
             $result[] = $query_post_type;
         }
         $result[] = 'archive';
     } elseif ($wp_query->is_archive()) {
         // archive-[post-type]
         // [post-type]
         // archive
         if ($query_post_type) {
             $result[] = 'archive-' . $query_post_type;
             $result[] = $query_post_type;
         }
         $result[] = 'archive';
     } elseif ($wp_query->is_page()) {
         // page-[parent-slug]-[post-slug]
         // page-[post-slug]
         // [page-template-name]
         // page
         // singular
         if ($post->post_parent) {
             if ($parent_slug = get_slug($post->post_parent)) {
                 $result[] = 'page-' . $parent_slug . '-' . $post_slug;
             }
         }
         $result[] = 'page-' . $post_slug;
         // page templates can have their unique names, let's add them before the fallback
         if ($page_template_name = get_page_template_name($post->ID)) {
             $result[] = $page_template_name;
         }
         $result[] = 'page';
         $result[] = 'singular';
     } elseif ($wp_query->is_attachment()) {
         // single-attachment-[slugfied-long-mime-type]
         // single-attachment-[slugfied-short-mime-type]
         // single-attachment
         // attachment
         // single
         // singular
         // slugfied-long-mime-type = image-jpeg
         // slugfied-short-mime-type = jpeg
         if (!empty($post->post_mime_type)) {
             $result[] = 'single-attachment-' . \Bond\to_slug($post->post_mime_type);
             $mime = explode('/', $post->post_mime_type);
             if (count($mime) > 1) {
                 $result[] = 'single-attachment-' . \Bond\to_slug($mime[1]);
             }
             $result[] = 'single-attachment-' . $mime[0];
         }
         $result[] = 'single-attachment';
         $result[] = 'attachment';
         $result[] = 'single';
         $result[] = 'singular';
     } elseif ($wp_query->is_single()) {
         // single-[post-type]-[post-slug]
         // single-[post-type]
         // [post-type]
         // single
         // singular
         $result[] = 'single-' . $post_type . '-' . $post_slug;
         $result[] = 'single-' . $post_type;
         $result[] = $post_type;
         $result[] = 'single';
         $result[] = 'singular';
     }
     // everything is handled, allow a filter and go
     $result = apply_filters($this->hooks_prefix . '/lookup_order', $result);
     return $result;
 }
开发者ID:andrefelipe,项目名称:bond,代码行数:101,代码来源:Bond.php


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