wordpress at zed1.com
Thu May 19 09:03:39 UTC 2011
On Wed, May 18, 2011 at 01:46, Dylan Kuhn <dylan.k.kuhn at gmail.com> wrote:
> For me it's a specific case, but one I seem to have to consider a lot. Map
> libraries, fancy slideshows, table enhancers, and such can all be fairly
> that content is often as likely to be in a widget or dependent instance of
> WP_Query as the main one.
> It's harder to make the decision in plugin code, because you have no idea
> how much content will need the scripts. Maybe it would be a nice plugin
> option to let the user choose their strategy, lookahead or global include.
One possible strategy is to save a reference to the post at the time the
content is generated. This could be looking for your short code (or whatever
triggers the need for JS) in the content *at the time it is saved* and
adding that post id to a list saved in an option. That way, the look up at
request time is very fast (the option will already be loaded) and simple
(looking for a post id in the retrieved content)
Of course, you will need to hook post saves, trashes, and deletes but that's
low overhead simply because it only occurs when the user alters content on
the back end.
Finally, if you need to cater for multiple loops, you can hook 'the_posts'
(late) to make your decision (to include in the footer).
More information about the wp-hackers