WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What php code can be used to find the page object that hosts the blogs?

Note that this may not be the same as the first page of the web site. In the admin section we can specify in which page to display the blog posts. The hard part from what I can see is how to get this info programatically. I can cycle through all the pages using get_pages() but the is_home() is only available within the context of the loop. I don't see a field on the page objects returned by get_pages() which indicates that it is a page with blog posts.

share|improve this question
up vote 10 down vote accepted

Hi @Alkaline:

I think you are looking for this:

// $page is a post where post_type=='page'
if (get_option('show_on_front')=='page') {
  $page_id = get_option('page_for_posts');
  $page = get_post($page_id);
} else {
  $page = false;
share|improve this answer
Thanks but this code returns the 'front page' which is not necessarily the blogs page. One can change this setting in the admin sectio using codex.wordpress.org/Settings_Reading_SubPanel Also, Wordpress provides two conditional tags is_home() and is_front_page(). I'm looking for the page that would test true to is_home(). Unfortunately these conditional tags are only available within the loop. – Alkaline Feb 28 '11 at 5:14
@Alkaline: You're looking for the page_for_posts option then. Just swap the option queried in Mike's code snippet. – wyrfel Feb 28 '11 at 5:46
Yes, I had a look a the get_option() and found the right param to use. Your use of get_option() led me to it. I'll award you the "correct answer" if you update your code. That way it won't mislead others. Cheers – Alkaline Feb 28 '11 at 5:52
@Alkaline and @wyrfel - Thanks guys, that's what I get for not testing. I had done that previously but I obviously switched the correct one. I'll update the answer for others. – MikeSchinkel Feb 28 '11 at 8:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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