Site logo

Archived topic

Which php file should I model for a custom taxonomy?

1 reply · Started by Josh on December 14, 2021

Viewing posts 1–2 of 2

I have a custom taxonomy (brand) for my CPT (hotel). I'm trying to have a page that is my "portfolio of brands" page. I believe the best way to do that is to have a normal page either create a shortcode with "get_terms()" or use a page template. Is there a better way to do this though? Is there a wordpress page template built in automatically?

The problem I am having is on that page when I have a user click through to an actual taxonomy term archive (I am not sure about the nomenclature for this page ) It loads the archive.php template. This means I should copy that page for my term template and name it "taxonomy-brand.php". Is that correct?

Assuming it is, what other file to do I need to pull into my child theme? there is a line that says "generate_do_template_part( 'archive' );" what is this pulling? Whichever file this is is that the only one i need to move to my child theme, or do I actually need to pull more than 1 file?

P.S. when I search this forum for "taxonomy.php" The site returns an error page...

Hi Josh,

By default, the theme pulls in this file:
https://github.com/tomusborne/generatepress/blob/master/archive.php

and this one: (For archive.php's content structure which is basically hooked in html elements)
https://github.com/tomusborne/generatepress/blob/master/inc/structure/archives.php

As for what template is loading:

By default, WordPress tries to look for the template appropriate to the queried page.

The hierarchy of what it looks for it this list -
https://developer.wordpress.org/themes/template-files-section/taxonomy-templates/#:~:text=The%20category%20hierarchy,index.php

It checks for #1 first, if #1 doesn't exist, it goes further down the line 'til it finds what it can use.
(if you scroll down the article I've linked, you'll see a similar hierarchy for custom taxonomies)

As for what you copy, you can try copying the contents of https://github.com/tomusborne/generatepress/blob/master/archive.php as a baseline and modify it to your preference.

This archived topic is closed to new replies.