Opened 8 years ago
Closed 8 years ago
#37655 closed enhancement (fixed)
[Template Hierarchy] category-slug.php cannot be properly loaded when slug is not English
Reported by: | withgjr | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-patch has-unit-tests |
Focuses: | template | Cc: |
Description
This problem can be reproduced very easily:
- Create a category using the language other than English. (In my case, Chinese)
- And create a category-slug.php file.
- And then you can see the Wordpress can not find the right template to load.
This problem is caused by the function 'get_category_template' in the wp-includes/template.php file.
Just change this line:
<?php if ( ! empty( $category->slug ) ) { $templates[] = "category-{$category->slug}.php"; $templates[] = "category-{$category->term_id}.php"; }
To:
<?php if ( ! empty( $category->slug ) ) { $decoded_slug = urldecode($category->slug); $templates[] = "category-{$decoded_slug}.php"; $templates[] = "category-{$category->term_id}.php"; }
And this problem can be solved.
Attachments (4)
Change History (13)
#1
@
8 years ago
- Component changed from General to Taxonomy
- Focuses template added
- Keywords has-patch added
- Version 4.5.3 deleted
#3
follow-up:
↓ 4
@
8 years ago
- Keywords needs-unit-tests added
@withgjr Thank you very much for your contribution! 37655.diff is perfectly fine.
get_category_template()
isn't the only function that would need need to be adjusted though. Also, automated tests are required to verify the existence of the bug and how the patch fixes it.
If you have experience in writing tests, any help is greatly appreciated. If not, some sample data to reproduce this (i.e. title & slug of the category you created) would be very helpful as well. That way, someone else can chime in and contribute tests.
#4
in reply to:
↑ 3
@
8 years ago
Chinese is my mother tongue, and I also can speak some Korean, so I choose this two languages as sample data.
I choose the word 'test' for this two language.
- 測試
- 테스트
You can use the words above as slug and title to reproduce the bug.
Replying to swissspidy:
@withgjr Thank you very much for your contribution! 37655.diff is perfectly fine.
get_category_template()
isn't the only function that would need need to be adjusted though. Also, automated tests are required to verify the existence of the bug and how the patch fixes it.
If you have experience in writing tests, any help is greatly appreciated. If not, some sample data to reproduce this (i.e. title & slug of the category you created) would be very helpful as well. That way, someone else can chime in and contribute tests.
#5
@
8 years ago
- Milestone changed from Awaiting Review to 4.7
- Owner set to johnbillion
- Status changed from new to reviewing
#6
@
8 years ago
37655.2.diff introduces the decoded form of template file names as an extra, higher-priority entry within the template hierarchy. This means that existing templates that use the URL-encoded form of the template name will continue to work.
Example:
Given a page with a slug of 測試
, the page template hierarchy now looks like:
page-測試.php
page-%e6%b8%ac%e8%a9%a6.php
page-123.php
page.php
singular.php
index.php
This applies to category archives, tag archives, taxonomy term archives, pages, and posts.
Tests are a work in progress and are dependent on #14310 which I hope to get in soon.
#7
@
8 years ago
- Keywords has-unit-tests 2nd-opinion added; needs-unit-tests removed
37655.3.diff is an updated patch with tests which demonstrate the updated template hierarchy when a post or term name includes multibyte characters. See comment:6 for the details.
I'd love to get this in. Any feedback from anyone?
Sorry, I have no experience on contributing Wordpress before. The newest 37655.diff file is the correct version. I don't know how to remove the wrong file '37655.patch'.