18

On the Reading Settings page you can set a "Front Page" and a "Posts Page". You can check whether the current page is_front_page();

Is there a similar function for the "Posts Page". I have noticed that is_page(); does not work for this special page.

Thanks

34

is_home() checks for the "Posts Page", despite the somewhat confusing function name.

  • thanks, i thought i checked them all, but i guess not... – mike Apr 14 '11 at 18:02
  • 3
    What about $wp_query->is_posts_page? – Weston Ruter May 15 '13 at 8:03
  • @WestonRuter has the correct answer to the question. – The J Jan 19 '17 at 13:49
6

Wordpress comes with 7 primary template page types, which can be determined on this way

if ( is_main_query() ) {
    // Error
    if ( is_404() ) {
        ;
    }
    // Front page
    if ( is_front_page() ) {
        ;
    }
    // Archive
    if ( is_archive() ) {
        ;
    }
    // Comments popup
    if ( is_comments_popup() ) {
        ;
    }
    // Search
    if ( is_search() ) {
        ;
    }
    // Singular
    if ( is_singular() ) {
        ;
    }
    // Home - the blog page
    if ( is_home() ) {
        ;
    }
}

is_home tells to you, that you have the blog page.

1

"Posts page" is usually an archive of:

  • posts of a category
  • posts of a tag
  • posts of a date ( year, month...)
  • posts of main archive

Each one of these can be checked by a one of the many conditional tags like is_category() is_tag() is_date() is_archive() And so many more. To get a better understanding head over to the codex http://codex.wordpress.org/Conditional_Tags

0

First check the blogs related things like author, tag, post type

function is_blog () {
        global  $post;
        $posttype = get_post_type($post );
        return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post')  ) ? true : false ;
  }

Now check and return something which you want to have

function check_post_type(){
    $postType;
    if (is_blog())
      {
         $postType = 'I am post';
      } else
       {
          $postType = 'I am page';
       };
    return $postType;
  }

Use it like Boss <?php echo check_post_type();?>

Thanks to Wes Bos

0

TL;DR

Case A. There is no need to determine it inside the main template file (index.php) because it is the default template for it[1].

Case B. To determine it inside a page template (ex: page.php), simply check it like so:

get_option( 'page_for_posts' ) == get_the_ID()

Details

I literally went digging the source-code[2] of it just to be able to know how wordpress does the checking of the value. It turns out, it is using the statement get_option( 'page_for_posts' ) to know the post ID of the selected value of the Posts page.

So yeah, for this purpose, there is no such official checker function that is similar to is_front_page().

As long as you know the ID of the page that you've selected then you can use it for the checking process.

References

  1. WordPress Codex, Theme Development, codex.wordpress.org/Theme_Development

  2. Source-code of SettingsReading Settings, github.com/WordPress/.../wp-admin/options-reading.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.