/** * Get current page "type" in the way WordPress handles it * * Concerned page types are: * * - 'default_home': default wordpress: auto-generated homepage => front-page.php * - 'front_page': user defined front page (homepage post) => front-page.php * - 'home': user defined blog page (post) => home.php * - 'search' * - '401' * - '403' * - '404' * - 'attachment': single attachment * - 'page': single post with type "page" * - 'post_sticky': single post with the featured option enabled * - 'post_XXX': single custom post type post * - 'post': single post * - 'tag': one tag archive * - 'category': one category archive * - 'author': single author / archive of author's posts * - 'post_type_archive_XXX': XXX custom post type archive * - 'post_type_archive': post type archive * - 'taxonomy': one taxonomy archive * - 'date': archive by date * - 'archive': global archive page * - 'index': this is the default type when no other one matches * * @return string */ function get_page_type() { global $page_type; if (!isset($page_type)) { $page_type = 'index'; if (is_front_page() && is_home()) { // default wordpress: auto-generated homepage => front-page.php $page_type = 'default_home'; } elseif (is_front_page()) { // user defined front page (homepage post) => front-page.php $page_type = 'front_page'; } elseif (is_home()) { // user defined blog page (post) => home.php $page_type = 'home'; } elseif (is_search()) { $page_type = 'search'; } elseif (is_401()) { $page_type = '401'; } elseif (is_403()) { $page_type = '403'; } elseif (is_404()) { $page_type = '404'; } elseif (is_single() && is_attachment()) { $page_type = 'attachment'; } elseif (is_page()) { $page_type = 'page'; } elseif (is_single() && is_sticky()) { $page_type = 'post_sticky'; } elseif (is_single()) { $post_type = get_post_type(); if ($post_type) { $page_type = 'post_' . $post_type; } else { $page_type = 'post'; } } elseif (is_archive() && is_tag()) { $page_type = 'tag'; } elseif (is_archive() && is_category()) { $page_type = 'category'; } elseif (is_archive() && is_author()) { $page_type = 'author'; } elseif (is_archive() && is_post_type_archive()) { $post_type = get_post_type(); if ($post_type) { $page_type = 'post_type_archive_' . $post_type; } else { $page_type = 'post_type_archive'; } } elseif (is_archive() && is_tax()) { $page_type = 'taxonomy'; } elseif (is_archive() && (is_date() || is_year() || is_month() || is_day() || is_time())) { $page_type = 'date'; } elseif (is_archive()) { $page_type = 'archive'; } } return $page_type; }
public function render() { /* @var $post \WP_Post */ global $post; $this->entries = array(); $this->addHomePage(); if (!is_front_page() && is_home()) { $show_on_front = get_option('show_on_front'); if ($show_on_front == 'page') { $this->addBlogPage(); } } elseif (is_tag()) { $this->addBlogPage(); $tag_id = get_query_var('tag_id'); $this->addTag($tag_id); } elseif (is_category()) { $this->addBlogPage(); $cat_id = get_cat_id(single_cat_title('', false)); $this->addCategory($cat_id); } elseif (is_author()) { $this->addAuthor(get_the_author_meta('ID')); } elseif (is_search()) { $this->addSearch(get_search_query()); } elseif (is_page()) { $this->addPage($post->ID); } elseif (is_single()) { $this->addBlogPage(); $categories = get_the_category(); if (isset($categories[0])) { $this->addCategory($categories[0]->cat_ID); } $this->addPost($post->ID); } elseif (is_401()) { $this->addErrorPage(401); } elseif (is_403()) { $this->addErrorPage(403); } elseif (is_404()) { $this->addErrorPage(); } elseif (is_tax()) { $this->addBlogPage(); $term = get_query_var('term'); $tax = get_query_var('taxonomy'); if ($tax == 'post_format') { $this->addPostFormat($term); } } elseif (is_archive()) { $this->addBlogPage(); $this->addDate(is_year() || is_month() || is_day() ? get_the_time('Y') : false, is_year() || is_month() ? get_the_time('m') : false, is_day() ? get_the_time('d') : false); } return $this->entries; }
/** * Process the body classes of 401 & 403 error pages * * To use this feature, write: * * add_filter('body_class', 'basicbootstrap_error_class'); * * The `body_class` filter is documented in `wp-includes/post-template.php`. * * @param $classes * @return array * @since WP_Basic_Bootstrap 1.0 */ function basicbootstrap_error_class($classes) { if (is_403()) { $classes[] = "error403"; } elseif (is_401()) { $classes[] = "error401"; } return $classes; }