[wp-hackers] Need A Hook (or advice)

Mark Jaquith mark.wordpress at txfx.net
Tue Feb 28 04:02:36 GMT 2006


On Feb 27, 2006, at 3:47 PM, Garett Harnish wrote:

> I need a way for a plugin to add a page to wp_list_pages.   I know  
> no hook exists to do this, and the only way I can think of  
> duplicating this functionality is ugly.

There's a wp_list_pages hook, but it operates on the text output of  
the entire function.  What I'd like eventually is to have  
wp_list_pages pass a hierarchial array through a different filter  
first, so you could use simple array manipulation to insert your  
stuff, instead of search/replace.

> I could have the plugin insert a page into the blog, but I just  
> need the page listed, I don't want it to be displayed like page.  I  
> want the contents to be PHP code from the plugin and I want the  
> page to remove itself if the plugin has been disabled (since it  
> won't work).

Does the page need to have a "nice" URI?  Or is it okay if the page  
points directly to your plugin?

In any case, you can use the wp_list_pages hook to do something like  
this:

> function add_garetts_link($text) {
> 	return $text . '<li class="page_item"><a href="' .  
> get_garetts_page_link() . '" title="Garett's Title">Link Text</a></ 
> li>';
> }
>
> add_filter('wp_list_pages', 'add_garetts_link', 50); // high number  
> so that other plugins get to have their way first

obviously you'd have to write get_garetts_page_link().

But anyway, that'll append your link to the end in the same style  
that wp_list_pages() adds page links.  It's a simplistic method, but  
it might do for your needs.  If you need the URI to look pretty, you  
have a lot more coding to do as you need to add a rewrite rule, and  
have the link generate the fancy version only if rewrite rules are  
being used, etc.

--
Mark Jaquith
http://txfx.net/




More information about the wp-hackers mailing list