- This topic has 10 replies, 2 voices, and was last updated 4 years, 4 months ago by
Tom.
-
AuthorPosts
-
January 30, 2019 at 8:43 pm #797257
Mike
Having trouble creating a custom template for a CPT and custom taxonomy category page.
I have a CPT with two custom taxonomies. I want to list the categories in one of those taxonomies in a sidebar widget (same behavior as the core Categories widget).
I created the categories widget two ways, first with a plugin, Custom Post Type Widgets, and then with a function in Snippets and a shortcode in a Custom HTML widget. Both work, and the results of clicking a category is displayed with the archive.php template.
I’m using a child theme. In it, I created a custom template named archive-[CPT NAME].php but that is not recognized, archive.php is still used. I also tried category.php and category-[CPT NAME].php, and taxonomy-[CPT NAME].php, but archive.php was still used.
This seems to be the same thing as described in Template file name for Category under Custom Post Type.
I’m using the CPT UI plugin to create CPTs and taxonomies.
What filename do I use to override archive.php?
January 31, 2019 at 8:13 am #797769Tom
Lead DeveloperLead DeveloperThose filenames should work as long as the CPT slug matches. Can you link me to one of those custom post type archives where it should be working?
January 31, 2019 at 12:11 pm #798029Mike
I put the link in the original post. The sidebar on the right is generated by the Custom Post Type Widgets widget, for the CPT “course” and taxonomy “topic”. Everything is associating properly, as the category listings are fine, it’s just changing the template.
For no logical reason, just to see, I even copied the archive.php file to the child theme, and the snippet I have that shows which template file a page is using (full path appears at bottom of page when in as admin) shows that archive.php is then used from the child theme as it should be.
Really hope it’s not something simple and stupid that I’ve done, because I go to great lengths not to post here in Support. But here I’ve tried everything I can think of. π
January 31, 2019 at 4:11 pm #798178Tom
Lead DeveloperLead DeveloperSo your
archive-[CPT NAME].php
would affect the content of your page. The link in your post is just a regular page – it’s not an archive.You can check by looking at the
<body>
classes. You’ll see WordPress thinks it’s just a regular page: http://prntscr.com/mf08flThat means it would be using the
page.php
template.Let me know if I’m misunderstanding π
January 31, 2019 at 10:10 pm #798327Mike
Situation: I have a custom post type (naem:
course
) with a custom category (name:topic
). Want a sidebar categories widget that displays thetopic
categories (should behave same as standard Categories widget). Used Custom Post Type Widgets plugin to create a CPT Categories widget here: right sidebar > “Course topics” widgetProblem: Trying to make a custom template for the category archive pages, but the WP template hierarchy doesn’t seem to be working. The
archive.php
template is called when you click the links in the widget, for example: a category archive page from that category widget. Whenarchive-course.php
ortaxonomy-topic.php
are present, the are not recognized.In the last link, look above left of the main page title for the text “this is archive.php” — I entered that in
archive.php
as a marker.These files are all there right now, but
archive.php
is still being used.in generatepress_child theme dir: archive.php archive-course.php taxonomy-topic.php
Only
archive.php
is being recognized, not eitherarchive-course.php
ortaxonomy-topic.php
.Hope that’s clearer!
February 1, 2019 at 9:20 am #798864Tom
Lead DeveloperLead DeveloperHmm, so in this case, it looks like
taxonomy-topic.php
should be the template: https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-taxonomiesI just did some looking around, and some people are saying that this issue was fixed when they re-saved their permalinks using the Post name option. Even if it’s already set, try clicking the save button again.
February 1, 2019 at 11:15 am #798974Mike
Nope. Ran across that suggestion in my searches, but didn’t seem to directly relate to this problem. But I just tried: saved permalinks Plain, then back to Post name, cleared browser cache, and tried in different browser, and same, only
archive.php
is used.How would you recommend creating a Categories widget for a CPT and custom taxonomy, with a custom template for its category archive page?
February 1, 2019 at 4:56 pm #799186Tom
Lead DeveloperLead DeveloperI thought you had the widget all working? We just need to figure out why the template isn’t working?
If you install the Query Monitor plugin, does it tell you the list of templates the page is using? Feel free to shoot me some login details once you install it if you want me to take a look: https://generatepress.com/contact
February 1, 2019 at 7:05 pm #799238Mike
Yes, the widget is working.
Will install Query Monitor and get back to you! π
February 1, 2019 at 10:47 pm #799301Mike
Grrr, SOLVED, and, in the end, it was something simple and stupid that I should’ve caught.
It was a wrong taxonomy template filename. Was uploading and renaming
archive.php
, and meant to rename ittaxonomy-topic.php
but actually enteredtaxonomy-course.php
(the CPT name, not the tax name). In my mind it was properly named, but not in reality… Noticed in Query Monitor.Thanks!!!!
February 2, 2019 at 8:06 am #799633Tom
Lead DeveloperLead DeveloperAha! Glad you got it working π
-
AuthorPosts
- You must be logged in to reply to this topic.