[wp-hackers] Plugin replacing a page based on http variables

Alex Günsche ag.ml2007 at zirona.com
Thu Sep 20 11:37:21 GMT 2007


On Thu, 2007-09-20 at 12:04 +0100, James Davis wrote:
> Alex Günsche wrote:
> 
> > The template_redirect hook will replace the actual output with yours.
> 
> That's almost, but not quite what I'm looking for. I'd like to output a
> 'page' in the style of the selected theme's page.php rather than one
> I've written myself. Something like the following pseudo-code.

I understand; unfortunately, that's not so simple. You see, when
WordPress receives a request, it will first determine what resource you
request (page, post, etc.), then select the template. It will also issue
a database query, create the content elements and run them through their
standard filters. After that, it will include the theme files and
execute the template functions herein.

This means for your plugin: You can either manipulate the output of one
or more *single* template functions (title, post/page content, comment
data, etc.), for example by modifying the DB query or using the API
filters. Or you can use a hook like template_redirect to replace the
content entirely.

However, you cannot "carve out" the middle of the template and fill it
with your stuff. You *could* find out which is the theme in use, include
its files and try to replace the main content section with a simple
parser. It might work for a couple of popular and/or standardized
themes, but it will fail on a large number of themes, simply because
there is not such a thing as a defined main section.

This means, you can replace the content and the header with whatever you
like, but the structure of the outcoming document will remain the same;
i.e. your replacements will still be at the same position as given in
the theme's template.

Kind regards,
Alex

-- 
Alex Günsche, Zirona OpenSource-Consulting
Blogs: http://www.zirona.com/ | http://www.regularimpressions.net
PubKey for this address: http://www.zirona.com/misc/ag.ml2007.asc



More information about the wp-hackers mailing list