Opened 15 years ago
Closed 14 years ago
#16312 closed defect (bug) (fixed)
is_category() returns false while in index
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 3.5 | Priority: | normal |
| Severity: | normal | Version: | 3.0.4 |
| Component: | Inline Docs | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
Let's say the incoming URL is your typical request for a top-level category, eg:
http://www.test.com/categorybase/Cat-A
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..
Attachments (1)
Change History (12)
#1
@
15 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#2
@
15 years ago
- 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
Ah, sorry, you meant inline docs.
#3
in reply to:
↑ description
;
follow-up:
↓ 6
@
15 years ago
Replying to FrancescoRizzi:
Then, WP calls index.php instead of (as one may expect) category.php - which may be debatable.
Actually a 404 template is used here (same for non-existing posts, pages, tags). According to Template Hierarchy, it can be index.php if 404.php doesn't exist in your theme.
If we decide to update the inline docs, I guess we also need to include that explanation
for all appropriate is_*() functions for consistency.
#4
follow-up:
↓ 5
@
15 years ago
I don't see the documentation issue here, to be honest. The category doesn't exist, so the request will 404 and the various flags will all be false, except for is_404. Same goes for pages, posts, really anything queryable.
#5
in reply to:
↑ 4
@
15 years ago
Replying to nacin:
I don't see the documentation issue here, to be honest. The category doesn't exist, so the request will 404 and the various flags will all be false, except for is_404. Same goes for pages, posts, really anything queryable.
I think the issue is that the inline doc don't hint at the actual behaviour in this scenario
Whether current page query contains a category name or given category name.
Is not the same as
Whether the current page query contains a category name, or given category name, and (if so) whether the category exists.
#6
in reply to:
↑ 3
@
15 years ago
Replying to SergeyBiryukov:
Replying to FrancescoRizzi:
Then, WP calls index.php instead of (as one may expect) category.php - which may be debatable.
Actually a 404 template is used here (same for non-existing posts, pages, tags). According to Template Hierarchy, it can be
index.phpif404.phpdoesn't exist in your theme.
That makes sense - thanks for explaining that bit of mystery to me. And to confirm: I did not have a 404.php template in my scenario.
If we decide to update the inline docs, I guess we also need to include that explanation
for all appropriateis_*()functions for consistency.
Agreed (at least, where applicable)
#7
@
15 years ago
There's a different description in current trunk:
Is the query for a category archive page?
This can probably be:
Is the query for an existing category archive page?
Indeed, fixing the Codex is the correct thing to do here.