[wp-trac] [WordPress Trac] #21620: Add conditional tag to check if current page is any of the blog-related pages
WordPress Trac
wp-trac at lists.automattic.com
Fri Aug 17 19:03:06 UTC 2012
#21620: Add conditional tag to check if current page is any of the blog-related
pages
--------------------------+-----------------------------
Reporter: grantnorwood | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords: dev-feedback
--------------------------+-----------------------------
The current is_home() function returns true when the blog's home page (or
paged > 2) is viewed, but I propose we should also have a convenient tag
to determine if the currently viewed page is '''any''' of the blog-related
pages. (Excludes custom post types.)
This would be a new function called is_blog_page(), and would return true
if the current post type is 'post', and if is_home(), is_archive(), or
is_single() also return true.
This is tangential but still related to the confusing names and
implementations of the is_home() and is_front_page() functions (see
#18705, #10158, #21237). However, I'm seeking to add a new function that
aligns with the existing (or future) names, but still gives the additional
functionality of detecting whether the current page is any of the blog
post pages, which is_home() does not do.
An example of the proposed new function is below:
{{{
/**
* WordPress' missing is_blog_page() function. Determines if the
currently viewed page is
* one of the blog pages, including the blog home page, archive,
category/tag, author, or single
* post pages.
*
* @return bool
*/
function is_blog_page() {
global $post;
//Post type must be 'post'.
$post_type = get_post_type( $post );
//Check all blog-related conditional tags, as well as the current post
type,
//to determine if we're viewing a blog page.
return (
( is_home() || is_archive() || is_single() )
&& ( $post_type == 'post' )
) ? true : false ;
}
}}}
I'm happy to attach a patch if that's helpful! I'd love to contribute to
core for the first time.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21620>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list