8

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.

1 Answer 1

13

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;
}
4
  • 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.
    – Bernard
    Commented Feb 28, 2011 at 5:14
  • 1
    @Alkaline: You're looking for the page_for_posts option then. Just swap the option queried in Mike's code snippet.
    – wyrfel
    Commented Feb 28, 2011 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
    – Bernard
    Commented Feb 28, 2011 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. Commented Feb 28, 2011 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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