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


PHP WP_Query::is_author方法代码示例

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


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

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

示例2: add_courses_to_author_archive

 /**
  * It ensures that the author archive shows course by the current user.
  *
  * This function is hooked into the pre_get_posts filter
  *
  * @param WP_Query $query
  * @return WP_Query $query
  */
 public function add_courses_to_author_archive($query)
 {
     if (is_admin() || !$query->is_author()) {
         return $query;
     }
     // this should only apply to users with the teacher role
     $current_page_user = get_user_by('login', $query->get('author_name'));
     if (!$current_page_user || !in_array('teacher', $current_page_user->roles)) {
         return $query;
     }
     // Change post types depending on what is set already
     $current_post_types = $query->get('post_type');
     if (empty($current_post_types)) {
         // if empty it means post by default, so add post so that it also includes that for now
         $new_post_types = array('post', 'course');
     } elseif (is_array($current_post_types)) {
         // merge the post types instead of overwriting it
         $new_post_types = array_merge($current_post_types, array('course'));
     } else {
         // in this instance it is probably just one post type in string format
         $new_post_types = array($current_post_types, 'course');
     }
     // change the query before returning it
     $query->set('post_type', $new_post_types);
     /**
      * Change the query on the teacher author archive template
      *
      * @since 1.8.4
      * @param WP_Query $query
      */
     return apply_filters('sensei_teacher_archive_query', $query);
 }
开发者ID:mattytemple,项目名称:YTC-Sensei,代码行数:40,代码来源:class-sensei-teacher.php

示例3: defineLookupOrder

 /**
  * The rule of this ordering is: from the most specific to the least.
  * Most of the default WP Template Hierarchy is the same, but not all is followed.
  *
  * For the full example of our lookup order plesase follow to:
  *
  * For the default WP hierarchy follow to:
  * http://codex.wordpress.org/Template_Hierarchy
  *
  * @param WP_Query $wp_query
  * @return array
  */
 protected function defineLookupOrder(\WP_Query $wp_query)
 {
     $result = [];
     if (!$wp_query) {
         return $result;
     }
     // prepare vars
     $post = !empty($wp_query->posts) ? $wp_query->posts[0] : false;
     $post_type = $post ? $post->post_type : false;
     $post_slug = $post ? $post->post_name : false;
     $query_post_type = $wp_query->query_vars['post_type'];
     if (is_array($query_post_type)) {
         // it's not usual to have multiple post types on a rewrite rule
         // but even if there is, it's extremely inconsistent to rely on
         // a template name with multiple post types
         // if that's the case, the user will have to alter the template
         // order manually
         $query_post_type = false;
     }
     // start the template hierarchy build up
     if ($wp_query->is_404()) {
         // 404-[post-type]
         // 404
         if ($query_post_type) {
             $result[] = '404-' . $query_post_type;
         }
         $result[] = '404';
     } elseif ($wp_query->is_search()) {
         // search
         // archive
         $result[] = 'search';
         $result[] = 'archive';
     } elseif ($wp_query->is_front_page()) {
         // if is page on front:
         // front-page
         // page
         // singular
         // if is posts on front:
         // front-page
         // home
         // archive-[post-type]
         // [post-type]
         // archive
         $result[] = 'front-page';
         if ($post_type) {
             if ($post_type !== 'page') {
                 $result[] = 'home';
                 $result[] = 'archive-' . $post_type;
                 $result[] = $post_type;
                 $result[] = 'archive';
             } else {
                 $result[] = 'page';
                 $result[] = 'singular';
             }
         }
     } elseif ($wp_query->is_home()) {
         // home
         // archive-[post-type]
         // [post-type]
         // archive
         $result[] = 'home';
         if ($post_type) {
             $result[] = 'archive-' . $post_type;
             $result[] = $post_type;
             $result[] = 'archive';
         }
         // for now this is not needed, test more
         // } elseif ($wp_query->is_post_type_archive()) {
         //     $result[] = 'archive-'.$query_post_type;
         //     $result[] = $query_post_type;
         //     $result[] = 'archive';
     } elseif ($wp_query->is_author()) {
         // author-[user-login]
         // author-[user-nicename]
         // author
         // archive
         if ($author = get_userdata($post->post_author)) {
             $result[] = 'author-' . $author->data->user_login;
             if ($author->data->user_login !== $author->data->user_nicename) {
                 $result[] = 'author-' . $author->data->user_nicename;
             }
         }
         $result[] = 'author';
         $result[] = 'archive';
     } elseif ($wp_query->is_tax() || $wp_query->is_tag() || $wp_query->is_category()) {
         // taxonomy-[taxonomy]-[term-slug]
         // taxonomy-[taxonomy]
         // taxonomy-[post-type]
//.........这里部分代码省略.........
开发者ID:andrefelipe,项目名称:bond,代码行数:101,代码来源:Bond.php


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