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


PHP WP_Query::is_page方法代码示例

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


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

示例1: pre_get_posts

 /**
  * Make any needed modifications to the main query
  * via pre_get_posts for the homepage or frontpage
  *
  * @since 2.3.0
  *
  * @param WP_Query $q Current WP_Query object at the time of pre_get_posts
  */
 public function pre_get_posts($q)
 {
     if (!$q->is_main_query() || !$q->is_home() && !$q->is_page() && !$q->is_archive()) {
         return;
     }
     // Static frontpage
     if ($q->is_page() && get_option('show_on_front') == 'page' && get_option('page_on_front') == $q->get('page_id')) {
         $templates = apply_filters('themeblvd_paginated_templates', array('template_list.php', 'template_list.php', 'template_builder.php'));
         $template = get_post_meta($q->get('page_id'), '_wp_page_template', true);
         if (in_array($template, $templates) && isset($q->query['paged'])) {
             $q->set('paged', $q->query['paged']);
         }
     }
     // Adjust posts_per_page if framework is in grid mode
     if ($q->is_archive() || $this->is_blog($q)) {
         // Check to make sure we're in grid mode
         if (themeblvd_is_grid_mode()) {
             $key = 'archive';
             if ($this->is_blog($q)) {
                 $key = 'index';
             }
             $columns = themeblvd_get_option("{$key}_grid_columns");
             if (!$columns) {
                 $columns = apply_filters('themeblvd_default_grid_columns', 3);
             }
             $rows = themeblvd_get_option("{$key}_grid_rows");
             if (!$rows) {
                 $rows = apply_filters('themeblvd_default_grid_rows', 4);
             }
             // Posts per page = $columns x $rows
             $q->set('posts_per_page', $columns * $rows);
         }
     }
     // Exclude any categories from posts page
     if ($this->is_blog($q)) {
         $cat = '';
         if (themeblvd_is_grid_mode()) {
             $exclude = themeblvd_get_option('grid_categories');
         } else {
             $exclude = themeblvd_get_option('blog_categories');
         }
         if ($exclude) {
             foreach ($exclude as $key => $value) {
                 if ($value) {
                     $cat .= sprintf('-%s,', $key);
                 }
             }
         }
         if ($cat) {
             $cat = themeblvd_remove_trailing_char($cat, ',');
             $q->set('cat', $cat);
         }
     }
     // Apply pagination fix when homepage custom layout
     // set over home "posts page"
     if (defined('TB_BUILDER_PLUGIN_VERSION') && $q->is_home() && 'custom_layout' == themeblvd_get_option('homepage_content')) {
         // Layout info
         $kayout_name = themeblvd_get_option('homepage_custom_layout');
         $layout_post_id = themeblvd_post_id_by_name($kayout_name, 'tb_layout');
         if ($layout_post_id) {
             $elements = get_post_meta($layout_post_id, 'elements', true);
         }
         // Loop through elements and look for that single
         // paginated element (there can only be one in a layout).
         if (!empty($elements) && is_array($elements)) {
             foreach ($elements as $area) {
                 if (!empty($area) && is_array($area)) {
                     foreach ($area as $element) {
                         switch ($element['type']) {
                             case 'post_grid_paginated':
                                 if (!empty($element['options']['rows']) && !empty($element['options']['columns'])) {
                                     $posts_per_page = intval($element['options']['rows']) * intval($element['options']['columns']);
                                 }
                                 $q->set('posts_per_page', $posts_per_page);
                                 break;
                             case 'post_list_paginated':
                                 if (isset($element['options']['source']) && 'query' == $element['options']['source']) {
                                     if (!empty($element['options']['query'])) {
                                         $custom_q = wp_parse_args(htmlspecialchars_decode($element['options']['query']));
                                     }
                                     if (isset($custom_q['posts_per_page'])) {
                                         $q->set('posts_per_page', $custom_q['posts_per_page']);
                                     }
                                 } else {
                                     if (!empty($element['options']['posts_per_page'])) {
                                         $q->set('posts_per_page', $element['options']['posts_per_page']);
                                     }
                                 }
                                 break;
                         }
                     }
                 }
//.........这里部分代码省略.........
开发者ID:JulieKuehl,项目名称:julie-jumpstart,代码行数:101,代码来源:class-tb-query.php

示例2: alter_event_page_request

 /**
  * Fix for events page rules if permalinks are disabled, unfortunatelly not too elegant.
  */
 public function alter_event_page_request($request)
 {
     if (!is_admin() && !get_option('permalink_structure') && isset($request['page_id'])) {
         $is_event_archive = false;
         // WPML & Polylang
         if (function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE')) {
             if ((int) $request['page_id'] === (int) icl_object_id(Events_Maker()->options['general']['pages']['events']['id'], 'page', true, ICL_LANGUAGE_CODE)) {
                 $is_event_archive = true;
             }
         } elseif ((int) $request['page_id'] === (int) Events_Maker()->options['general']['pages']['events']['id']) {
             $is_event_archive = true;
         }
         // is requested page an event archive page?
         if ($is_event_archive === true) {
             // the query isn't run if we don't pass any query vars
             $query = new WP_Query();
             $query->parse_query($request);
             if ($query->is_page()) {
                 unset($request['page_id']);
                 $request['post_type'] = 'event';
             }
         }
     }
     return $request;
 }
开发者ID:patlegris,项目名称:On-Off,代码行数:28,代码来源:class-query.php

示例3: alter_request

 /**
  * Alternates request
  *
  * @param array $request
  * @return array
  */
 public function alter_request($request)
 {
     if (is_admin()) {
         return $request;
     }
     $mapping = array();
     foreach ($this->get_post_types() as $post_type) {
         $page_id = (int) g1_get_theme_option('post_type_' . $post_type, 'page_for_posts');
         if ($page_id) {
             $mapping[$post_type] = $page_id;
         }
     }
     foreach ($mapping as $post_type => $page_id) {
         // WPML fallback
         if (function_exists('icl_object_id')) {
             $page_id = absint(icl_object_id($page_id, 'page', true));
         }
         if ($page_id) {
             // The query isn't run if we don't pass any query vars
             $query = new WP_Query();
             $query->parse_query($request);
             // Change request from page to post type archive
             if ($query->is_page()) {
                 if (absint($query->get('page_id')) === $page_id || strlen($query->get('pagename')) && absint($query->get_queried_object_id()) === $page_id) {
                     unset($request['page']);
                     unset($request['page_id']);
                     unset($request['pagename']);
                     $request['post_type'] = $post_type;
                 }
             }
         }
     }
     return $request;
 }
开发者ID:aragonc,项目名称:3clicks,代码行数:40,代码来源:features.php

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