admin管理员组文章数量:1022935
I have custom post type "project", and it is loading with the template "archive-project".
I already have a page "applications" to load "archive-project"
So the same page is accessible via both URL's
www.example/project
www.example/applications
I tried a plugin "smart Archive Page Remove", which doesn't work for me.
How to remove the www.example/project
Please help.
I have custom post type "project", and it is loading with the template "archive-project".
I already have a page "applications" to load "archive-project"
So the same page is accessible via both URL's
www.example/project
www.example/applications
I tried a plugin "smart Archive Page Remove", which doesn't work for me.
How to remove the www.example/project
Please help.
Share Improve this question edited Apr 28, 2019 at 21:23 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Apr 28, 2019 at 8:44 VivekVivek 439 bronze badges 5 |1 Answer
Reset to default 2It seems that your archive-project.php
is using a custom query to display the posts. And you have declared it as Page template by adding Template Name
in a comment block, so you are able to assign it to applications
page. As the result www.website/applications
loads this template file.
www.website/project
also uses the same template file because of its file name archive-project.php
. This is how Wordpress works.
Wordpress uses its Template File Hierarchy to display posts and pages on front-end.
For Custom Post Types with 'has_archive' => true
wordpress use the following order of template files to render the archive:
archive-{post_type}.php
– If the post type isproject
, WordPress will look forarchive-project.php
archive.php
index.php
The post displayed by above files are selected and fetched from db using main query, so no custom query is required here.
However, some developers choose to create a Custom Page Template for displaying the archive of posts. This file can have any valid file name e.g. my-awsome-template.php
. However, care should be taken to avoid file names that collide with standard wordpress template file names. e.g. archive.php
or archive-project.php
etc.
These template files are created by adding Template Name
in a comment block, something like this.
<?php
/*
Template Name: My Custom Page
*/
It’s a good idea to choose a name that describes what the template does as the name is visible to WordPress users when they are editing the page. For example, you could name your template Homepage
, Blog
, or Portfolio
.
Now this template can be assigned to any pages on the Page > Edit screen.
One of the characteristic of custom templates is the use of custom queries to fetch and display posts from db usin WP_Query
or get_posts()
and generally does not use Wordpress main query.
The Solution
How to remove the www.website/project
You are using custom page template to display the archive and do not want to use mechanism used by wordpress to display archive of posts. So set 'has_archive' => false
where you register your post type project
. It is also recommended to rename the archive-project.php
to something else.
I have custom post type "project", and it is loading with the template "archive-project".
I already have a page "applications" to load "archive-project"
So the same page is accessible via both URL's
www.example/project
www.example/applications
I tried a plugin "smart Archive Page Remove", which doesn't work for me.
How to remove the www.example/project
Please help.
I have custom post type "project", and it is loading with the template "archive-project".
I already have a page "applications" to load "archive-project"
So the same page is accessible via both URL's
www.example/project
www.example/applications
I tried a plugin "smart Archive Page Remove", which doesn't work for me.
How to remove the www.example/project
Please help.
Share Improve this question edited Apr 28, 2019 at 21:23 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Apr 28, 2019 at 8:44 VivekVivek 439 bronze badges 5- 1 It's loading with the template archive-project (i.e. archive-project.php)? Why can't you just delete that file? – tmdesigned Commented Apr 28, 2019 at 8:55
- @tmdesigned When i delete archice-project, design breaks – Vivek Commented Apr 28, 2019 at 9:03
-
Do you use a custom query in
archive-project.php
and given it aTemplate Name
that you assigned toapplications
page? – Qaisar Feroz Commented Apr 28, 2019 at 9:35 - @QaisarFeroz both are loading same archive-project.php – Vivek Commented Apr 28, 2019 at 9:40
-
@Vivek, that is clear from your question that both urls load same template file. I wanted to know how
archive-project.php
is codded. Please reply to my previous comment clearly so I may be able to resolve the issue or at least guide you in right direction. – Qaisar Feroz Commented Apr 28, 2019 at 9:51
1 Answer
Reset to default 2It seems that your archive-project.php
is using a custom query to display the posts. And you have declared it as Page template by adding Template Name
in a comment block, so you are able to assign it to applications
page. As the result www.website/applications
loads this template file.
www.website/project
also uses the same template file because of its file name archive-project.php
. This is how Wordpress works.
Wordpress uses its Template File Hierarchy to display posts and pages on front-end.
For Custom Post Types with 'has_archive' => true
wordpress use the following order of template files to render the archive:
archive-{post_type}.php
– If the post type isproject
, WordPress will look forarchive-project.php
archive.php
index.php
The post displayed by above files are selected and fetched from db using main query, so no custom query is required here.
However, some developers choose to create a Custom Page Template for displaying the archive of posts. This file can have any valid file name e.g. my-awsome-template.php
. However, care should be taken to avoid file names that collide with standard wordpress template file names. e.g. archive.php
or archive-project.php
etc.
These template files are created by adding Template Name
in a comment block, something like this.
<?php
/*
Template Name: My Custom Page
*/
It’s a good idea to choose a name that describes what the template does as the name is visible to WordPress users when they are editing the page. For example, you could name your template Homepage
, Blog
, or Portfolio
.
Now this template can be assigned to any pages on the Page > Edit screen.
One of the characteristic of custom templates is the use of custom queries to fetch and display posts from db usin WP_Query
or get_posts()
and generally does not use Wordpress main query.
The Solution
How to remove the www.website/project
You are using custom page template to display the archive and do not want to use mechanism used by wordpress to display archive of posts. So set 'has_archive' => false
where you register your post type project
. It is also recommended to rename the archive-project.php
to something else.
本文标签: custom post typeshow to remove pages loading with the archive templates
版权声明:本文标题:custom post types - how to remove pages loading with the archive templates 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745543567a2155291.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
archive-project.php
and given it aTemplate Name
that you assigned toapplications
page? – Qaisar Feroz Commented Apr 28, 2019 at 9:35archive-project.php
is codded. Please reply to my previous comment clearly so I may be able to resolve the issue or at least guide you in right direction. – Qaisar Feroz Commented Apr 28, 2019 at 9:51