is_category() returns false while in index
|Reported by:||FrancescoRizzi||Owned by:||nacin|
|Component:||Inline Docs||Keywords:||has-patch commit|
Let's say the incoming URL is your typical request for a top-level category, eg:
Let's say Cat-A doesn't exist.
Finally, let's say the theme includes both index.php and category.php.
Then, WP calls index.php instead of (as one may expect) category.php - which may be debatable. However, what I think is a bug is that under these conditions, a call to is_category() from within index.php returns false. At least, according to the docs in the source, I would expect it to return true:
Whether current page query contains a category name or given category name. The category list can contain category IDs, names, or category slugs. If any of them are part of the query, then it will return true.
The URL, in fact, did include /categorybase/Cat-A
Yes, WP may not be able to tell that Cat-A is supposed to be a category because, as stated above, Cat-A does not exist...
The fix may be simply to document that is_category determines
Whether current page query contains a category name or given category name (matching only existing categories).
Alternatively, is_category could return true for any query that looks like a requets for a category archive (possibly: any URL starting with the base prefix + category base + anything beyond that) - which may be the spirit of is-category (or not - you make the call)
I'm marking this as bug just because I don't know any better - but I can see the argument that this should be categorized as enhancement or a doc issue..
Change History (12)
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
- Component changed from General to Query
- Keywords needs-patch added; category removed
- Milestone set to Future Release
- Resolution invalid deleted
- Status changed from closed to reopened