splscs
splscs

Reputation: 71

Wordpress is_page() for blog post listing page

I'm trying to use an is_page() conditional in Wordpress to detect whether or not the current page is the blog listing page (or a blog post page actually). The conditional works fine for any other page (contact, whats-on etc) but for some reason it doesn't work for the blog page.

Plus the actual blog post pages - URLs are www.domain.com/the-post-title format, so I can't check for 'blog' in the URL from $_SERVER or anything. Any help would be hugely appreciated.

Upvotes: 2

Views: 6937

Answers (3)

Alex Vauch
Alex Vauch

Reputation: 301

We need to check:

  • if this page is blog page.
  • if this page is "page for posts"

    function is_page_for_posts() {
        $result = false;
    
        if ( is_home() && ! is_front_page() ) {
            $page = get_queried_object();
    
            $result = ! is_null( $page ) && $page->ID == get_option( 'page_for_posts' );
        }
    
        return $result;
    }
    

Upvotes: 2

user850010
user850010

Reputation: 6359

According to this article, this is how you use these kind of conditional functions:

if ( is_front_page() && is_home() ){
    // Default homepage
} elseif ( is_front_page()){
    //Static homepage
} elseif ( is_home()){
    //Blog page
} else {
    //everything else
}

Upvotes: 0

Robert Lee
Robert Lee

Reputation: 1561

You may need to do a combination of is_home() - if your home page is the blog

or is_single() based on the type of blog post

reference: http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page

Upvotes: 0

Related Questions