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


PHP WP_Query::is_month方法代码示例

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


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

示例1: getPageObject

 /**
  * Parse which page we are on using URL
  */
 public function getPageObject($pageUrl)
 {
     global $wp_rewrite;
     // If post type, we are using url_to_postid function
     $postId = url_to_postid($pageUrl);
     if ($postId) {
         $postType = get_post_type_object(get_post($postId)->post_type);
         return array('value' => $postId, 'title' => get_the_title($postId), 'type' => get_post($postId)->post_type, 'label' => is_array($postType->labels) ? $postType->labels['name'] : $postType->labels->name);
     }
     $path = str_replace(get_site_url(), '', $pageUrl);
     $path = trim($path, '/');
     // If path is empty, then it is front page
     if (empty($path)) {
         return array('value' => get_option('page_on_front') ? get_option('page_on_front') : '', 'title' => '', 'type' => 'front_page', 'label' => __('Home Page'));
     }
     // Otherwise, we will try to match through rewrite or by query
     $rewrite = $wp_rewrite->wp_rewrite_rules();
     if (is_array($rewrite) && count($rewrite) > 0) {
         foreach ($rewrite as $match => $query) {
             if (preg_match("#^{$match}#", $path, $matches) || preg_match("#^{$match}#", urldecode($path), $matches)) {
                 $query = preg_replace("!^.*\\?!", '', $query);
                 $query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
                 parse_str($query, $query_vars);
                 break;
             }
         }
     } else {
         $query = preg_replace("!^.*\\?!", '', $path);
         parse_str($query, $query_vars);
     }
     // Workaround for fail pagename rewrite match
     if (isset($query_vars['pagename']) && strpos($query_vars['pagename'], '?') !== false) {
         $query = preg_replace("!^.*\\?!", '', $query_vars['pagename']);
         parse_str($query, $query_vars);
     }
     $querypost = new WP_Query($query_vars);
     if ($querypost->is_date()) {
         if ($querypost->query_vars['m']) {
             $date = $querypost->query_vars['m'];
         } else {
             if ($querypost->is_day()) {
                 $date = $querypost->query_vars['year'] . zeroise($querypost->query_vars['monthnum'], 2) . zeroise($querypost->query_vars['day'], 2);
             } else {
                 if ($querypost->is_month()) {
                     $date = $querypost->query_vars['year'] . zeroise($querypost->query_vars['monthnum'], 2);
                 } else {
                     if ($querypost->is_year()) {
                         $date = $querypost->query_vars['year'];
                     }
                 }
             }
         }
         return array('value' => $date, 'title' => '', 'type' => 'archive', 'label' => __("Archive"));
     } else {
         if ($querypost->is_category() || $querypost->is_tag() || $querypost->is_tax()) {
             $tax_query = $querypost->tax_query->queries;
             $taxonomy = get_taxonomy($tax_query[0]['taxonomy']);
             if ($tax_query[0]['field'] == 'term_id') {
                 $term_id = $tax_query[0]['terms'][0];
             } else {
                 if ($tax_query[0]['field'] == 'slug') {
                     $term_id = get_term_by('slug', $tax_query[0]['terms'][0], $taxonomy->name)->term_id;
                 }
             }
             return array('value' => $term_id, 'title' => get_term($term_id, $taxonomy->name)->name, 'type' => $taxonomy->name, 'label' => is_array($taxonomy->labels->name) ? $taxonomy->labels['name'] : $taxonomy->labels->name);
         } else {
             if ($querypost->is_search()) {
                 return array('value' => $querypost->query_vars['s'], 'title' => '', 'type' => 'search', 'label' => __("Search"));
             } else {
                 if ($querypost->is_home()) {
                     return array('value' => '', 'title' => '', 'type' => 'home', 'label' => __("Blog Home Page"));
                 }
             }
         }
     }
 }
开发者ID:HasClass0,项目名称:mainwp-child,代码行数:79,代码来源:MainWPHeatmapTracker.class.php


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