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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745543569a4632236.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