admin管理员组文章数量:1384587
I want to create a new theme file in wordpress. for example : index111.php And I want to copy all the contents of one of the main template files (for example : index.php) into the new file (index111.php). And then I want to make changes to its codes.
And I want to set a URL for this file (index111.php) so that by entering this URL in the browser, this file will be loaded and displayed. for example : mysite/index111
I want to do this several times. For example, create 100 customized files with a dedicated URL.
My WP theme is Avada.
What should I do?
I want to create a new theme file in wordpress. for example : index111.php And I want to copy all the contents of one of the main template files (for example : index.php) into the new file (index111.php). And then I want to make changes to its codes.
And I want to set a URL for this file (index111.php) so that by entering this URL in the browser, this file will be loaded and displayed. for example : mysite/index111
I want to do this several times. For example, create 100 customized files with a dedicated URL.
My WP theme is Avada.
What should I do?
Share Improve this question asked Apr 24, 2020 at 8:48 sizdahsizdah 33 bronze badges1 Answer
Reset to default 1You cannot directly create index111.php
go to mysite/index111
. Because the WordPress loading principal is like the following explanation. You could do similar things with custom templates but not exactly the index111.php
. Also, it is assumed that you use permalinks
too.
WordPress loading method
Because WordPress is running a query based system. That's means, basically it read links like mysite/?p=1234
and find if there is any post with 1234
. If you turned on permalinks with Post name
(settings -> permalinks) with Post name
selected and saved.
Then it allows mysite/something
where something
is a page you have created in Pages
menu on the left. It then try to match if there is a page something
and find its id, if page exists, it loads, redirect to 404 if not. WordPress regard something
as slug
. When you create a page, a post, slug
will be automatically generated based on the title you insert. Characteristic of a slug
- Editable
- Unique, if slug found in the database, WordPress will add number to your new slug. You could have pages with same title but their slug could not.
It is editable.
*** So what method to use depends on what did you try to accomplish.
To accomplish what you would like, there are many ways, here illustrate 2 simple methods which you could refer. If you understand the above concept well, there are still other ways to do so by using custom codes and more advanced methods.
by Template for Page Selection
Step to add
- create a template page and save as filename
template-{$name}.php
- add a page and select this template from Template list on the right sidebar in the Edit Page menu
<?php
/**
* The example template for index111, the following "index111" will be displayed from the selection menu
*
* Template Name: index111
*
* @package myPackage
*/
get_header(); ?>
<!-- content here -->
<?php
get_footer();
pros
- could select page template from the edit page menu when adding a new page
- don't need to pre-create all pages
- could apply to many different pages with same template
by page-{$slug}.php template
You create page with same slug with the template file. Steps
- You add a page in Pages menu, name it with
index111
with slugindex111
, - create
page-index111.php
in your theme. Then when you go tomysite/index111
, it will load page-index111.php.
pros
- could have custom template for each template
cons
- need to create each page to use respective template with same slug name
- if you need 100 templates, then you need to create 100 pages
- because it use slug to create, template name must be unique, if you would like to use same set of elements, you might need to add a separate files and the require it.
本文标签: phpHow set a custom URL for a new theme file in WP
版权声明:本文标题:php - How set a custom URL for a new theme file in WP? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744536349a2611340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论