简体   繁体   中英

Wordpress- Creating an archive template

I am trying to create a custom archive template for my categories. I have a parent category called member-resources , which is a parent category for multiple other categories .

I do not want to access these categories by /category/member-resources . According to wordpress documentation for template hierarchy, I need to create archive-member-resources.php and change the php code to display as needed.

However this template is not the one being rendered(archive.php is always being rendered), and if I try to access it by entering /member-resources I get a 404..

What am I missing ? thanks

[EDIT]

Excuse my wordpress skills as I have only been working with it for about a month..

I asked this question for a very simple reason. I worked on a project, in which I ended up with a massive archive.php file with alot of conditional logic such as :

  • if( is_category('events') ) , render a side menu
  • if( is_category('news') ) , render something else
  • if( is_category('member-resources') ) render pagination

    This is just an example, but I wanted to highlight that with different categories, I might want to call a completely different archive template( if at all possible ), rather than having a large file which is not very maintainable..

If this cannot be done, please provide me with a solution, so that on my next project, I wouldn't run into this problem again.

You should not use any type of archive page (archive.php, category.php, taxonomy.php etc) as a listings/index page. That is not what archive pages are intended for. Also, the template hierarchy specific to archive-xxx.php is for custom post types, not categories.

The main query on any archive page is quite specific and should not be tampered with on template level. It totally destroys pagination and common logic within the main query.

You should make use of a page template. Just simply copy your page.php, rename it to page-xxx.php, add the necessary page header and modify it as needed

For further reading

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM