• I need to get the ID of the Posts Page as set in Settings->Reading.

    the $post variable seems to only return information about the posts contained within the page how do I get the ID of the page itself?

    I’m using the featured image in a banner (outside the loop) so I need the ID to reference the thumbnail.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Which template file are you working on?

    Thread Starter chrispink

    (@chrispink)

    I’m making a child theme based on 2013. The template is the default template (unaltered) but I’ve replaced the custom header function with a banner based on the featured image – this code is within header.php

    Which works on all single pages but not on the posts page. I haven’t made category pages yet but I’m guessing I may have the same problem

    When I echo $post->ID I get the ID of the first post listed rather than the page itself.

    Im using this;
    $thumbnail_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); // set up for banner picture

    to retrieve the featured image URL.

    Which template file are you working on?

    Thread Starter chrispink

    (@chrispink)

    Index.php

    the ‘posts page’ when set under dashboard – settings – reading has this ID:

    get_option('page_for_posts')

    try something like:

    if( is_home() && get_option('page_for_posts') ) { $page_id = get_option('page_for_posts');
    } elseif( is_page() ) { $page_id = $post->ID; }

    (untested; details might need to be adapted to your existing code)

    To find the page that contains the posts (the listing of posts), you use:

    get_option('page_for_posts')

    as alchymyth said.

    $posts_page_id = get_option( 'page_for_posts' );
    echo "posts page id: " . $posts_page_id;

    The caveat is that this value will only be set if you assign a static page for your front page and assign another page for your posts page (via Settings->Reading). When you run WordPress where the front page displays your blogs posts, that’s a special case and there is no “posts page” id. (actually, I think it comes back as 0).

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Posts Page ID’ is closed to new replies.