Want to display entries of a Custom Post Type on its archive page grouped by the custom taxonomy terms?
We are going to check if there's at least one term assigned to any of the published entries and if so, remove the default loop and add a custom loop with the code for displaying CPT entries organized by their custom taxonomies. If none of the published entries has been assigned to any taxonomy term, then the standard Genesis loop will be shown.
In this example, I have used Pods for registering "KB Items" (kbitem
) CPT and a corresponding "KB Categories" (kbcategory
) custom taxonomy.
Tip: Make sure you check "Enable Archive Page" in the advanced options when creating/editing your CPT in Pods.
Step 1
Create a file named archive-<cpt>.php
where cpt
is the name of your CPT having the code below. In this example, the file is named archive-kbitem.php.
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Thanks very much for this tutorial! I’m testing on a test site 🙂
I’m having some trouble with the template “as is” no changes.
I used kbcategory as the custom taxonomy name. Uploaded archive template to Magazine Pro (active theme).
But the archive display is as if using index.php. No taxonomy grouping.
Plugin “What the File” confirmed the archive display was archive-hdh_kbitem.php (my CPT).
I added the custom taxonomy to Post Meta, under the Post Title, so you can see what category each Post is in.
Added CSS, too. No joy.
Can you provide me with WP login so I can troubleshoot this?
https://sridharkatakam.com/contact/
I found my error. Sorry for the bother. Will press on with 2 columns conversion. Thanks!
Ok, good.
archive-kbitem.php. Lines 41-49
I think it would be helpful to be able to set the sort of posts
http://robincornett.com/custom-query/
Here’s an example: https://gist.github.com/srikat/1b0f9b26f92194c25745#file-gistfile1-php-L39-L40
That will display the posts in ascending order of their titles.
Apparently some solutions are simple – thanks very much!
How can I display the tax-term name on a single-kbitem.php for that specific post?
This plugin may help with “Knowledgebase” CPTs.
https://wordpress.org/support/view/plugin-reviews/jc-submenu
Another option
https://wordpress.org/plugins/category-posts-in-custom-menu/
[…] tutorial is somewhat related to Displaying CPT entries grouped by Custom Taxonomies in Genesis and is a result of this Facebook […]