php - Polylang and template files

admin2025-01-07  8

I divided the website i am making in diferent template files for example: Category for blog -> category-blog.php Category for projects -> category-projects.php But now I am using the POLYLANG plug in to make the translations. I've noticed that while i am creating the respective category in other languages the template does not apply for example category-blog.php file does not apply to the category-blog.php in other languages. Is any way that i can use the same category template file to multiple categories?? more specifically to the translations of the same category ?

Sorry if my questions seems confusing !

Thanks in advance !

I divided the website i am making in diferent template files for example: Category for blog -> category-blog.php Category for projects -> category-projects.php But now I am using the POLYLANG plug in to make the translations. I've noticed that while i am creating the respective category in other languages the template does not apply for example category-blog.php file does not apply to the category-blog.php in other languages. Is any way that i can use the same category template file to multiple categories?? more specifically to the translations of the same category ?

Sorry if my questions seems confusing !

Thanks in advance !

Share Improve this question asked Dec 20, 2019 at 9:40 Pedro FerreiraPedro Ferreira 1791 silver badge10 bronze badges 4
  • which theme do you use ? – Kaperto Commented Dec 20, 2019 at 9:45
  • I am using a custom made theme by me :/ (made from scratch) – Pedro Ferreira Commented Dec 20, 2019 at 9:47
  • ok I thought the theme may have a special way of handling. but I remember that for the file category-projects.php, the string projects is the slug for the category in one language. then if you have the category projects_spanish, you can create the file category-projects_spanish.php and put inside <?php require "category-projects.php"; – Kaperto Commented Dec 20, 2019 at 10:15
  • That's what i am trying to avoid i followed this tutorial digitalize.ca/2009/06/… – Pedro Ferreira Commented Dec 20, 2019 at 11:50
Add a comment  | 

1 Answer 1

Reset to default 0

One option is to create a single category.php file with conditionals. So, you would have something like this:

<?php
if(is_category('one') || is_category('un') {
// your code here
} elseif(is_category('two') || is_category('deux') {
// your code here
}
?>

This way you can still output different code per category, but you won't have to copy category-one.php to category-un.php etc.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736253428a123.html

最新回复(0)