[wp-hackers] "Posts page" feature and is_page()

Eric Marden wp at xentek.net
Sat Mar 29 18:41:07 GMT 2008


>
> If you want to know whether you're on the posts page, use
>
> $wp_query->is_posts_page
>
> There ought to be a function...

I agree. Here is my version of this function:

function is_posts_page () {
	global $wp_query;

	return $wp_query->is_posts_page;
}

But the more I played with this, the more I realized I needed more  
than just this.

For one, and this may be by design, but there is nothing to test  
whether this feature turned on or not, except by testing  
get_option('page_for_posts') - which returns the ID if this option is  
turned on, and nothing if it doesn't (because the entry in the DB is  
either there or not). A more 'authoritative' test function may be  
warranted.

There is a function get_page_link, but yet you can't get the link from  
the page object (get_page(get_option('page_for_posts'),OBJECT)), as  
guid was empty when I played with it. So it means that when you want  
to build a menu item for a page, it looks something like this:

$posts_page = get_page(get_option('page_for_posts'),OBJECT);
<a href="<?php echo get_page_link(get_option('page_for_posts')); ?>"  
title="<?php echo $posts_page->post_title; ?>"><?php echo $posts_page- 
 >post_title; ?></a>

And last but not least, wp_list_pages doesn't seem to allow you to  
apply css or other attributes to the output. If I could do this, and  
do this selectively (i.e. by page ID, similar to exclude) I probably  
wouldn't have needed the other hackery to make this work, as all I  
wanted to do was apply .current_page_item to the posts page menu item  
in my theme.

Am I just missing something and there is an easier way to do this, or  
do I just have a special case WP can't handle elegantly yet?

Thanks for all your help so far,

-e


More information about the wp-hackers mailing list