Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 7 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
1  
@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

 
discard

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.