[wp-hackers] Plugin custom page

Chris Taylor - stillbreathing.co.uk chris at stillbreathing.co.uk
Tue Nov 20 19:54:53 UTC 2012


Thanks Mike, but won't that return the first post filtered, then the
rest of the posts unfiltered? Something like:

Post 3
... my filtered content ...

Post 2
... content ...

Post 1
... content ...

I'm starting to think I'm going about this entirely wrong! There must
be an easy way to create a custom page with a plugin, isn't there?

Thanks for the continued help,

Chris



On Tue, Nov 20, 2012 at 5:45 PM, Mike Little <wordpress at zed1.com> wrote:
> On 20 November 2012 17:18, Chris Taylor - stillbreathing.co.uk <
> chris at stillbreathing.co.uk> wrote:
>
>> Hi,
>>
>> Thanks for the replay but this is (ignoring abstractions) exactly what
>> I'm doing. I've got a URL like this:
>>
>> mysite.com/?voucher=abc123
>>
>> Which then uses template_redirect to check if a voucher is being
>> requested, then uses add_filter( 'the_content', ...) to change the
>> content that is being output to display my form. The problem is that
>> when the site homepage is displaying multiple blog entries (as a
>> standard installation does) then the add_filter( 'the_content', ...)
>> call gets run *once per post* leading to multiple instances of my
>> modified content down the page.
>>
>> I need a way to say "when this querystring parameter is set display
>> this content once and once only, within the page/single/index
>> template".
>>
>>
> Quick solution: Remove your filter in the filter code itself.
>
> add_filter( 'the_content', 'my_content_filter');
> function my_content_filter($content) {
>  if ( some_test() ) { // check my special conditions
>      $content .= add_my_extra_content();
>      remove_filter( 'the_content', 'my_content_filter');
>  }
> return $content;
> }
>
>
> Mike
> --
> Mike Little
> http://zed1.com/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list