Determine if page is the Posts Page

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.

Read More

Thanks

Related posts

Leave a Reply

6 comments

  1. 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

  3. 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

  4. 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 Settings › Reading Settings, github.com/WordPress/…/wp-admin/options-reading.php