Community Forums › Forums › Archived Forums › Design Tips and Tricks › Building a custom taxonomy page
Tagged: Custom Post Type, taxonomy, taxonomy archive page
- This topic has 9 replies, 2 voices, and was last updated 11 years, 4 months ago by John.
-
AuthorPosts
-
December 13, 2012 at 1:06 pm #5015NWTDMember
I'm building a child theme on the Genesis Framework and am curious on how I might build an archive page for a custom taxonomy.
I've created a custom post type and three custom taxonomies. I'd like to build an archive page for these customized taxonomies.
A little further customization would be to order the archives alphabetically by title.
Any thoughts or ideas would be great. Thanks in advance!
December 13, 2012 at 10:40 pm #5164JohnParticipantnwtech,
This is how I would do that: create a template file called "archive-[your-custom-post-type] and add the following code on that page:
// Customize the Loop
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_loop', 'my_cpt__taxonomy_custom_loop');function my_cpt__taxonomy_custom_loop() {
global $paged;
global $query_args; // any wp_query() args
// Get term
$term = get_query_var( 'term' );
$args = array( 'order' => 'ASC',
'orderby' => 'title',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'first-taxonomy',
'field' => 'slug',
'terms' => $term
),
array(
'taxonomy' => 'second-taxonomy',
'field' => 'slug',
'terms' => $term
),
array(
'taxonomy' => 'third-taxonomy',
'field' => 'slug',
'terms' => $term
)
),
'paged' => $paged
);
// Accepts WP_Query args (http://codex.wordpress.org/Class_Reference/WP_Query)
genesis_custom_loop( wp_parse_args( $query_args , $args ) );
} // End my_cpt__taxonomy_custom_loopLet me know if that works for you,
JohnEdit: the code editor is stripping out the angle brackets, so keep that in mind if you copy and paste the code.
John Sundberg | blackhillswebworks.com
A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉December 14, 2012 at 10:01 am #5217JohnParticipantSince that code didn't paste very well I created a Gist where it should be rendered correctly:
https://gist.github.com/4286425
John Sundberg | blackhillswebworks.com
A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉December 15, 2012 at 6:58 am #5389NWTDMemberThanks for the quick response John!
I'm still a novice when it comes to PHP, so forgive my ignorance with my questions.
With the above code, I assume I still have to have my <php> tags at the top and bottom? And looking at the code you provided, is it correct that this archive page will be listing all three custom taxonomies? Ideally, I'd like a separate page for each of the taxonomies...is that feasible by adjust the above code and making three different archive pages?
December 15, 2012 at 12:14 pm #5426JohnParticipantI guess I should have added that detail - you can simply make a copy of your theme's page.php, archive.php, or something similar, rename it like I mentioned above, and add that code to the new file. If your child theme doesn't have one of those files you can find one in the Genesis folder.
The important thing is that it has the opening php tag and the closing genesis(); function, with your code in between.
Actually, this code should handle all three taxonomies, but one term at a time. You won't need a separate file for each taxonomy. A real-life example is this page on a site I built for my wife, which displays a custom post type called 'organizations' that has four different taxonomies: http://aheartforjustice.com/organizations/
Clicking on any of the taxonomy terms will display an archive page for that taxonomy term, listed alphabetically by 'slug'. I adjusted the code I posted for you to list the posts by the title of the taxonomy term instead of the slug.
Let me know if I'm not tracking with you on what you're wanting to do.
John
John Sundberg | blackhillswebworks.com
A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉December 17, 2012 at 12:18 pm #5775NWTDMemberAwesome. And actually I'd like to build a page similar to what you have there. In that you have what appears to be other taxonomies listed (states and countries). I assume that organizations is a post type or is that a taxonomy as well?
To give an example of what I'm trying to accomplish, I'm converting this static HTML site into WordPress: http://patiodepot-inc.com/AreasWeService/State-CALIFORNIA/
So with these custom post types I've created, I'd set a taxonomy for the location and then services provided in that location. In the example I provided, if you were to click on any one item, you'd then be sent to a second taxonomy page that lists the services for that area. Then clicking on any particular service takes you to the post of this custom post type. I hope this is all making sense.
I know this seems super convoluted for what it is, but it's how the customer wants it and I'm just trying to make it work with this Genesis child theme.
Thanks again for your help and input.
December 17, 2012 at 1:30 pm #5797NWTDMemberDetailed information on what I've built so far:
Custom Post Type Name: Local Pages
Taxonomy 1: Locations
Taxonomy 2: Services
Taxonomy 3: KeywordsDecember 20, 2012 at 11:53 am #6451JohnParticipantOn that page I linked to Organizations is the custom post type, and countries, states, services, and names (alphabetically) are the taxonomies for that post type.
That looks like a big project you're working on there, and I wonder if it should be handled differently than how I did my wife's site. I'd have to set aside some think time to wrap my mind around that, and things are getting busy around here.
I think what's throwing me is the term "Local Pages" - I'm not sure what you mean by that. Sounds maybe too similar to the Locations taxonomy?
Anyhow, let me know how it goes for you and include a link when it's under way, if you don't mind.
John Sundberg | blackhillswebworks.com
A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉December 20, 2012 at 12:05 pm #6460NWTDMember"Local Pages" is a term coined by the client, thus used for him to cause less confusion...it really could be anything else. Trying to get my head around this whole thing and make the most logical sense to make this work most efficiently for my client and I.
Do you offer consulting? I'd be happy to pay you for your time if you have some more input regarding this interesting situation.
December 20, 2012 at 12:19 pm #6468JohnParticipantYeah, I could do that. Why don't you send me a note using the contact form on my website and we can go from there.
John Sundberg | blackhillswebworks.com
A WordPress developer’s toolbox: Firebug | WordPress Codex | Google 😉 -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.