Opened 12 years ago
Closed 12 years ago
#22031 closed enhancement (duplicate)
Conditional tags don't work within add_feed() callback function
Reported by: | sanchothefat | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Feeds | Keywords: | |
Focuses: | Cc: |
Description
I was putting together a custom feed and wanted to pick a different template based on the context of where I was in the site. So for example I wanted one feed template on the home/front page and another for category pages.
Using add_feed()
and browsing to that feed results in only is_feed()
being true and not any of the other conditional tags.
I was wondering if a) there's a reason for that and b) if it's something we could fix.
I'm not entirely sure where to look though. Attempts at running $wp_query->parse_query_vars()
to force the conditionals to be set were unsuccessful.
The following code is a quick demo:
add_feed( 'new_feed', 'feed_output' ); function feed_output() { if ( is_home() ) echo 'home feed'; if ( is_singular() ) echo 'singular feed'; if ( is_category() ) echo 'category feed'; }
Nothing will be output on /feed/new_feed/ URLs even if on home, single or category page.
Change History (4)
#3
@
12 years ago
@ocean90 I get what you're saying. Thing is though feeds change depending on context eg. /category/cat-name/feed/
is a feed for that category, so wouldn't it be useful to have a way of telling them apart from the main feed for example?
What about feed versions of the is_category()
type conditionals eg. something like is_category_feed()
, is_tax_feed()
etc...?
My use case for this was generating alternate views of the same context for a WordPress to kindle feed.
It doesn't make sense to return true for
is_home
oris_singular
in a feed. It's a feed sois_feed
returns true. You need to define your own query for the feed content.Example: