custom post types - how to remove pages loading with the archive templates

I have custom post type "project", and it is loading with the template "archive-project".I already h

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 a Template Name that you assigned to applications 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
Add a comment  | 

1 Answer 1

Reset to default 2

It 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:

  1. archive-{post_type}.php – If the post type is project, WordPress will look for archive-project.php
  2. archive.php
  3. 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

相关推荐

  • custom post types - how to remove pages loading with the archive templates

    I have custom post type "project", and it is loading with the template "archive-project".I already h

    19小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信