How to apply a template to the a CPT's 'home'?

Hi,

I have a CPT called ‘discuss’ (using ‘post’ capability) and have templates for:

Posts: /discuss/category/post-slug
Category pages: /discuss/category

But for /discuss I can’t figure out how to apply a template.

It’s an Archive page for sure but… what do I select in the template condition?

Thanks,

Lawrence

Hi Lawrence,

I hope I have known your question correctly and I capture my setting screen for your reference.

Regards,

Lux

Hi,

Interestingly, I have the template set to Single and it was working correctly on a category page.

I changed it to Archive but it didn’t solve the problem.

Do I need to have a Page created for /discuss?

I might exclude /discuss from from the template condition and treat it as a page instead. Which means creating another template, but that’s OK if it works.

The options of the template must correspond to the condition settings in the template. You need to separate two templates.

1)The option to create a single template and set the post type to the corresponding cpt.
2)Create a template to archive and set the internal template to archive to correspond to you. Taxonomy. If no custom taxonomy is set, select the corresponding category or all posts.

In your situation, is it that neither the template preview nor the front end can display the correct archive post or is it just that the front end cannot be displayed? Because I encountered a more interesting situation, the single page is normal but the arcive page is only correct when previewing. If it is on the front end, it will be redirected to the homepage. I don’t know the reason for this.

Hi,

I did what you suggested and it worked. The ‘home page’ of the CPT is a Page, and created a new template for it.

I haven’t come across the issue you described. Perhaps its a configuration issue with how you have set up the CPT, via a plugiin or using code?

Hi,
My problem has been solved. For some reason, the CPT archive slug did not work as expected. Later, after re-saving the permalinks settings in WP, it worked normally.

cheers

1 Like