Support » Developing with WordPress » Page instead of Term Archive Page

  • I have created a Custom Post Type (Courses) with custom taxonomy (Category) and created a term (Professional). I have read through some of the docs but could not understand how I can show a page instead of the term’s archive page.

    For the taxonomy it could be resolved by adding ‘has_archive’ => false.
    But how can I do this with taxonomies/terms?

    What I want is that
    “/courses/professional” shows a page “Professional Courses” and NOT the archive page that lists all courses within that term!

    I will be happy about your help!!!

    PS: I have tried to solve this by using a term template (taxonomy-coursescategory-professional.php) and associating it with my page “Professional Courses”. This does not work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Why bother with the custom taxonomy if you don’t want a list? You could just name your post Professional, and put what you want to see into the content.
    I think you had the right idea for the template, but maybe you named it incorrectly. Did you look at the Template Hierarchy?
    But that is only for displaying what is already queried. If you want to show something different, you need to modify the query, and that doesn’t scale well. That’s why it seems that you are using a taxonomy for the wrong thing.

    When I wrote my theme, I included a page template for taxonomy root, because WP is always querying for posts/pages. So if you have a URL like example.com/category/ you will get a 404 instead of a list of all the categories. My page template uses the slug of the page as the taxonomy and shows the list of terms (not posts). But you have to create the Page and assign that template. You could do something similar.

    Thread Starter ekn

    (@ekndev)

    Why bother with the custom taxonomy if you don’t want a list?

    Because the posts (courses) we be shown as a list but within a tabbed view that the user can adjust. Also the post structure given by custom taxonomy enables better usability in the backend and in the frontent a consistent permalink structure.

    Yes, I had a look at Template Hierarchy, and also the naming seems correct, since the template got recognized. But the assignment of custom page with the template did not work out well. Maybe I have to read more about the query. Basically, it would be enough to show the WYSIWYG-content. Any help on how the query has to be? (I tried to copy page template content but it did not work).

    Thanks

    The query is done by WordPress, based on the permalink structure. That determines which template file to load. If you want the template to deliver something else, you have to either use a filter on pre_get_posts to adjust the main query (which will then load a different template file), or ignore the query in your template and do another query for the data you want.
    Doing another query is where it doesn’t scale well, because how do you associate the Page with the taxonomy term? Is it by slug or what? You have to have a way to query the right page for the term.

    Or just change how you want your URLs to look.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page instead of Term Archive Page’ is closed to new replies.