admin管理员组

文章数量:1326633

I understand that you can create (as per the WordPress Hierarchical Structure) a specific template to load a specifc template.

For example:

category-new-york.php 

^ this is a priority over simply:

category.php

My question is, would creating a template PER US State be a "bad idea?"

So, I would have:

category-alabama.php 
category-arizona.php 
category-akansas.php 

etc etc

I say "bad practice" because perhaps I am just adding a ton of overhead that WordPress has to loop through templates - or is it not a huge problem? Would the overhead be nominal?

Thanks

I understand that you can create (as per the WordPress Hierarchical Structure) a specific template to load a specifc template.

For example:

category-new-york.php 

^ this is a priority over simply:

category.php

My question is, would creating a template PER US State be a "bad idea?"

So, I would have:

category-alabama.php 
category-arizona.php 
category-akansas.php 

etc etc

I say "bad practice" because perhaps I am just adding a ton of overhead that WordPress has to loop through templates - or is it not a huge problem? Would the overhead be nominal?

Thanks

Share Improve this question asked Aug 5, 2020 at 12:49 HenryHenry 9831 gold badge8 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I say "bad practice" because perhaps I am just adding a ton of overhead that WordPress has to loop through templates - or is it not a huge problem? Would the overhead be nominal?

No, there won't be an extra performance cost because that's not how the template loading works. WP always runs through the template hierarchy from most specific to most generic, testing if the file exists as it goes along. It doesn't "loop" through them.

As for creating a template for every US state, I would advise against it, mainly because it means your folder will have a lot of files making it difficult to navigate in the editor, and when you want to make a change you have to update every single state.

You'd be better off making a single generic state template, or better yet, add a state taxonomy and create taxonomy-state.php instead of repurposing categories.

本文标签: categoriesHaving a template per category Bad for server overhead