Building a custom taxonomy page

Community Forums Forums Design Tips and Tricks Building a custom taxonomy page

This topic is: not resolved

This topic contains 9 replies, has 2 voices, and was last updated by  John 1 year, 10 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #5015

    NWTD
    Participant
    Post count: 61

    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!

    
    
    		
    	
    #5164

    John
    Participant
    Post count: 157

    nwtech,

    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_loop

    Let me know if that works for you,
    John

    Edit: 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 ;)

    • This reply was modified 1 year, 10 months ago by  John. Reason: Note RE angle brackets in code
    • This reply was modified 1 year, 10 months ago by  John. Reason: Note RE angle brackets in code
    #5217

    John
    Participant
    Post count: 157

    Since 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 ;)

    #5389

    NWTD
    Participant
    Post count: 61

    Thanks 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?

    #5426

    John
    Participant
    Post count: 157

    I 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 ;)

    • This reply was modified 1 year, 10 months ago by  John. Reason: fixed typo
    • This reply was modified 1 year, 10 months ago by  John. Reason: fixed typo
    #5775

    NWTD
    Participant
    Post count: 61

    Awesome. 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.

    #5797

    NWTD
    Participant
    Post count: 61

    Detailed information on what I’ve built so far:

    Custom Post Type Name: Local Pages
    Taxonomy 1: Locations
    Taxonomy 2: Services
    Taxonomy 3: Keywords

    • This reply was modified 1 year, 10 months ago by  NWTD. Reason: formatting
    • This reply was modified 1 year, 10 months ago by  NWTD. Reason: formatting
    #6451

    John
    Participant
    Post count: 157

    On 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 ;)

    #6460

    NWTD
    Participant
    Post count: 61

    “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.

    #6468

    John
    Participant
    Post count: 157

    Yeah, 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 ;)

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.