[wp-hackers] Best practice for early access of post data

Claude Needham gxxaxx at gmail.com
Mon Sep 19 19:57:24 UTC 2011


On Sun, Sep 18, 2011 at 9:15 AM, Mike Little <wordpress at zed1.com> wrote:

> You might also want to look into the 'body_class' filter. Most css
> customisation based on the contents of the page can be done by simply adding
> a class to the body tag.
>
> If I want to peek at the content of the loop for the purposes of modifying
> something in the theme (usually in the header), I hook onto
> action 'template_redirect', which is suitably late in the process,
> but guaranteed to be before any theme code has run (apart from earlier hooks
> from functions.php). I can safely loop through the results detect/extract
> what I need, then rewind_posts() when I've finished to put everything back.
>

Mike,

Thanks for the followup.
Couldn't check it out until today. When I went to the body_class page
I found a bit of sample code doing exactly what I need. Pretty sweet
when ya get lucky like that.

Thanks for the heads up about the template_redirect too. That looks
very interesting. With some nice possibilities.

Regards,
Claude


More information about the wp-hackers mailing list