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


PHP WP_Query::is_archive方法代码示例

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


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

示例1: _fw_ext_portfolio_theme_action_set_posts_per_page

/**
 * Display all existing portfolio posts on the page (without pagination)
 * Because in this theme we use the https://mixitup.kunkalabs.com/ plugin to display portfolio posts
 * If your theme displays portfolio posts in a different way, feel free to change or remove this function
 * @internal
 * @param WP_Query $query
 */
function _fw_ext_portfolio_theme_action_set_posts_per_page($query)
{
    if (!$query->is_main_query()) {
        return;
    }
    /**
     * @var FW_Extension_Portfolio $portfolio
     */
    $portfolio = fw()->extensions->get('portfolio');
    $is_portfolio_taxonomy = $query->is_tax($portfolio->get_taxonomy_name());
    $is_portfolio_archive = $query->is_archive() && isset($query->query['post_type']) && $query->query['post_type'] == $portfolio->get_post_type_name();
    if ($is_portfolio_taxonomy || $is_portfolio_archive) {
        $query->set('posts_per_page', -1);
    }
}
开发者ID:halkibsi,项目名称:Unyson,代码行数:22,代码来源:hooks.php

示例2: is_pronamic_events_query

/**
 * Check if the query is requesting event post type
 *
 * @param WP_Query $query
 * @return boolean true if events are queried, false otherwises
 */
function is_pronamic_events_query(WP_Query $query)
{
    $is_pronamic_events = false;
    if ($query->is_archive() && !$query->is_tax('pronamic_event_status')) {
        // Check 'post_type' var
        // Note: post_type could also be an array
        $post_type = $query->get('post_type');
        if (!empty($post_type) && !is_array($post_type)) {
            $is_pronamic_events = post_type_supports($post_type, 'pronamic_event');
        }
        if (!$is_pronamic_events) {
            // Check queried object
            $object = $query->get_queried_object();
            $is_pronamic_events = isset($object, $object->name) && post_type_supports($object->name, 'pronamic_event');
        }
    }
    return $is_pronamic_events;
}
开发者ID:joffcrabtree,项目名称:wp-pronamic-events,代码行数:24,代码来源:functions.php

示例3: 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

示例4: tst_main_query_mods

function tst_main_query_mods(WP_Query $query)
{
    // exclude account_deleted's tasks:
    if (!is_admin() && $query->is_main_query()) {
        if (is_tag() && !$query->get('post_type')) {
            $query->set('post_type', 'tasks');
        }
        $query->set('author', '-' . ACCOUNT_DELETED_ID);
    }
    if ($query->is_main_query() && $query->is_archive() || $query->get('post_type') == 'tasks') {
        if (!empty($_GET['st'])) {
            $query->set('post_status', $_GET['st'] == '-' ? array('publish', 'in_work', 'closed') : $_GET['st']);
        }
        if (!empty($_GET['dl'])) {
            $metas = (array) $query->get('meta_query');
            switch ($_GET['dl']) {
                case '10':
                    $metas[] = array('key' => 'deadline', 'value' => array(date('Ymd'), date('Ymd', strtotime('+10 days'))), 'compare' => 'BETWEEN', 'type' => 'DATE');
                    break;
                case 'lm':
                    $metas[] = array('key' => 'deadline', 'value' => array(date('Ymd'), date('Ymd', strtotime('+1 month'))), 'compare' => 'BETWEEN', 'type' => 'DATE');
                    break;
                case 'mm':
                    $metas[] = array('key' => 'deadline', 'value' => array(date('Ymd', strtotime('+1 month')), date('Ymd', strtotime('+6 months'))), 'compare' => 'BETWEEN', 'type' => 'DATE');
                    break;
            }
            $query->set('meta_query', $metas);
        }
        if (!empty($_GET['rw'])) {
            $metas = (array) $query->get('meta_query');
            $metas[] = array('key' => 'reward', 'value' => $_GET['rw'], 'compare' => '=');
            $query->set('meta_query', $metas);
        }
        if (!empty($_GET['tt'])) {
            $query->set('tag_slug__in', (array) $_GET['tt']);
        }
    }
}
开发者ID:rizomaa,项目名称:ITVolunteer,代码行数:38,代码来源:customizer.php

示例5: pre_get_posts

 /**
  *    pre_get_posts
  *
  * @access 	public
  * @param 	\WP_Query $WP_Query
  * @return 	\WP_Query
  */
 public function pre_get_posts(WP_Query $WP_Query)
 {
     //EEH_Debug_Tools::printr( $WP_Query, '$WP_Query  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
     if (!$WP_Query->is_main_query() && !$WP_Query->is_archive()) {
         return $WP_Query;
     }
     //		$WP_Query->set( 'post_type', array( $this->CPT['post_type'] ));
     //		$WP_Query->set( 'fields', 'ids' );
     return $WP_Query;
 }
开发者ID:aaronfrey,项目名称:PepperLillie-GSP,代码行数:17,代码来源:EE_CPT_Strategy.core.php

示例6: query_points_to_archive

 /**
  * @param $query_string string
  *
  * Checks if the WP_Query functionality can decisively recognize if a querystring points
  * towards an archive.
  *
  * @return bool
  */
 private static function query_points_to_archive($query_string)
 {
     $root_page_actions = wpml_get_root_page_actions_obj();
     remove_action('parse_query', array($root_page_actions, 'wpml_home_url_parse_query'));
     $query_string = str_replace('?', '', $query_string);
     $query = new WP_Query($query_string);
     $is_archive = $query->is_archive();
     add_action('parse_query', array($root_page_actions, 'wpml_home_url_parse_query'));
     return $is_archive;
 }
开发者ID:edgarter,项目名称:wecare,代码行数:18,代码来源:wpml-root-page.class.php

示例7: query_points_to_archive

 /**
  * @param $query_string string
  *
  * Checks if the WP_Query functionality can decisively recognize if a querystring points
  * towards an archive.
  *
  * @return bool
  */
 private static function query_points_to_archive($query_string)
 {
     remove_action('parse_query', 'wpml_home_url_parse_query');
     $query_string = str_replace('?', '', $query_string);
     $query = new WP_Query($query_string);
     add_action('parse_query', 'wpml_home_url_parse_query');
     return $query->is_archive();
 }
开发者ID:tlandn,项目名称:akvo-sites-zz-template,代码行数:16,代码来源:wpml-root-page.class.php

示例8: 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

示例9: filter_children_from_query

 /**
  * Don't show child posts on the front page of the site, they'll be pulled in separately as updates to a live post.
  *
  * @param WP_Query $query The current query
  *
  * @return WP_Query
  */
 public function filter_children_from_query(WP_Query $query)
 {
     $post_type = $query->get('post_type');
     // only applies to indexes and post format
     if (($query->is_home() || $query->is_archive()) && (empty($post_type) || in_array($post_type, apply_filters('livepress_post_types', array('post'))))) {
         $parent = $query->get('post_parent');
         if (empty($parent)) {
             $query->set('post_parent', 0);
         }
     }
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:18,代码来源:livepress-post-format-controller.php

示例10: elseif

 /**
  * @param bool|String $requested_url String If this is specified the value of $url will be checked for whether it's the root page.
  *                       Checks whether the currently requested page is the root page.
  *
  * @return bool
  */
 function is_root_page($requested_url = false)
 {
     /*
      * A request leads to the root page under the following conditions.
      *
      * 1. The get parameter on it specifically requests the root page via either:
      *  ?preview_id = {root_page_id}
      *  ?page_id = {root_page_id}
      *  ?p = {root_page_id}
      *
      * 2. The root page slug is the first slug after the domain.
      *
      * 3. There is no slug after the domain and the get parameters are not set as to redirect
      *    to another page meaning:
      *  no ?p, ?page_id or similar query parameter redirects to another post/page
      *  no get parameter such as ?cat redirects to an archive page
      *
      */
     $is_root = true;
     // before checking anything see if the site even uses a root page
     $urls = $this->get_setting('urls');
     if (!$urls || !isset($urls['directory_for_default_language']) || !$urls['directory_for_default_language'] || !isset($urls['root_page']) || $urls['root_page'] == 0) {
         $is_root = false;
     } elseif (isset($_SERVER['REQUEST_URI']) || $requested_url !== false) {
         $root_id = $urls['root_page'];
         $root_slug = false;
         if ($root_id) {
             $root_page_object = get_post($root_id);
             if ($root_page_object && isset($root_page_object->post_name)) {
                 $root_slug = $root_page_object->post_name;
             }
         }
         if ($root_slug === false) {
             $is_root = false;
         } else {
             if ($requested_url) {
                 $request_uri = parse_url($requested_url, PHP_URL_PATH);
                 $query_string = parse_url($requested_url, PHP_URL_QUERY);
                 if ($query_string) {
                     $request_uri .= '?' . $query_string;
                 }
             } else {
                 $request_uri = $_SERVER['REQUEST_URI'];
             }
             //If the get parameter ? is not preceeded by a /, add a '/'
             if (strpos($request_uri, '?') !== false && strpos($request_uri, '/?') === false) {
                 $request_uri = str_replace('?', '/?', $request_uri);
             }
             $request_uri = wpml_strip_subdir_from_url($request_uri);
             //First get the slug of the requested url, should there be one.
             $slugs_and_get_params = explode('/', $request_uri);
             foreach ($slugs_and_get_params as $key => $slug) {
                 if (!trim($slug)) {
                     unset($slugs_and_get_params[$key]);
                 }
             }
             // if we have any slugs or get parameters it could be we are not on the root page
             if (!empty($slugs_and_get_params)) {
                 $get_query_string = '';
                 // First of all see if we have get parameters
                 if (isset($_GET) && !empty($_GET)) {
                     $get_query_string = array_pop($slugs_and_get_params);
                     /* In case we have get parameters we can instantly be sure to be on the root page
                      * This can be done by either id parameters or by slug/name parameters.
                      * ID parametes as of WP 4.1 are : p, page_id
                      * Name parameters as of WP 4.1 are: name, pagename
                      */
                     if (isset($_GET['p']) && $_GET['p'] != $root_id || isset($_GET['page_id']) && $_GET['page_id'] != $root_id || isset($_GET['name']) && $_GET['name'] != $root_slug || isset($_GET['pagename']) && $_GET['pagename'] != $root_slug) {
                         $is_root = false;
                     }
                 }
                 /*
                  * Next up there are other get parameters that allow us to recognize not being on the root page for certain.
                  * These only come into play when neither of the above page parameters is set and therefore no specific page is queried for.
                  */
                 if (!(isset($_GET['pagename']) || isset($_GET['name']) || isset($_GET['page_id']) || isset($_GET['p']))) {
                     /* The under these conditions excluded parameters, that ensure the root page to not be queried for, are determined in this way:
                      * First we fetch all rewrite rules. This has to be done from the options cache since the actual rewrite object is not initialized yet.
                      * Initializing it would impose a siginificant performance hit too.
                      */
                     $query = new WP_Query(str_replace('?', '', $get_query_string));
                     if ($query->is_archive()) {
                         $is_root = false;
                     }
                 }
                 // In case we have slugs, we need to check the last slug for whether it is the slug of the root page
                 if ($is_root && !empty($slugs_and_get_params)) {
                     $slugs = $slugs_and_get_params;
                     $last_slug = array_pop($slugs);
                     $second_slug = array_pop($slugs);
                     if (($root_slug != $last_slug && !is_numeric($last_slug) || is_numeric($last_slug) && $second_slug != null && $root_slug != $second_slug && 'page' != $second_slug) && (!(isset($_GET['p']) && $_GET['p'] == $root_id) || !(isset($_GET['page_id']) && $_GET['page_id'] == $root_id) || !(isset($_GET['name']) && $_GET['name'] == $root_slug) || !(isset($_GET['pagename']) && $_GET['pagename'] == $root_slug))) {
                         /* If the last slug is not the root slug or numeric,
                          * then the current page is not the root page. This condition only holds though
                          * in case no page/post parameters are appended to the request, that point towards the root page.
//.........这里部分代码省略.........
开发者ID:evilqubit,项目名称:cish,代码行数:101,代码来源:sitepress.class.php

示例11: is_issue_archive

 /**
  * Determine if the query is the main query for an issue archive
  *
  * @param WP_Query $query
  * @return bool
  */
 private function is_issue_archive($query)
 {
     if (!$query->is_main_query()) {
         return FALSE;
     }
     if (get_query_var('post_type') != 'issue') {
         return FALSE;
     }
     if (!$query->is_archive()) {
         return FALSE;
     }
     return TRUE;
 }
开发者ID:jbrinley,项目名称:BuggyPress,代码行数:19,代码来源:BuggyPress_IssueFilterPage.php

示例12: 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

示例13: paginationFix

 /**
  * Fix for custom loop pagination in custom taxonomy archives.
  *
  * @param Request $request Page request
  * @return Request
  */
 public function paginationFix($request)
 {
     if (!thb_array_contains($this->_type, array('post', 'page')) && $this->isPublicContent()) {
         $dummy_query = new WP_Query();
         $dummy_query->parse_query($request);
         $thb_works_taxonomies = $this->getTaxonomies();
         foreach ($thb_works_taxonomies as $tax) {
             if (isset($request[$tax->getType()])) {
                 if ($dummy_query->is_front_page() || $dummy_query->is_archive()) {
                     $posts_per_page = thb_get_option($this->getType() . '_per_page');
                     if (!empty($posts_per_page)) {
                         $request["posts_per_page"] = $posts_per_page;
                     }
                 }
             }
         }
     }
     return $request;
 }
开发者ID:alfredpp,项目名称:sarath-portfolio,代码行数:25,代码来源:class.posttype.php


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