29

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

6 Answers 6

48

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

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

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.

2

"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

2

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

1
  • this one just helped me when customizing the post.php edit for pages only.
    – Jonatas CD
    Commented May 4, 2021 at 13:31
1

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

1

https://codex.wordpress.org/Conditional_Tags in WordPress Codex sais that you can reference pages like so:

if ( is_front_page() && is_home() ) {
  // Default homepage
} elseif ( is_front_page() ) {
  // static homepage
} elseif ( is_home() ) {
  // blog page
} else {
  //everything else
}

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