Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

A WordPress Question

This is directed toward Zac Gordon, though anyone can answer if they feel they know how to approach this.

I have written and re-written this and there is no easy way to explain what I am trying to do, so ask questions if you are confused.

The hierarchy of the section I am trying to build is as follows: Category -> Sub Category -> Posts specific to Sub-Category I have custom post types and custom fields for this section. so ACF plugin is installed.

I may be over-thinking this, I have most of it working except the last part which is the Posts specific to the Sub-Category.

My Categories are pulled from the default Pages post type in WordPress. I created a Navigation out of them, the Sub Categories are also default Page post types which dropdown from their specific navigation items. So lets say the section I am working with is: Category-1 The user clicks Category-1 on the Navigation. A dropdown pops up with the following: Sub-Category-A Sub-Category-B Sub-Category-C I have 1 Custom Page Template set up already that filters the content based on the post->post_name (which is basically the ending slug in the URL) so if a user types mysite.com/category-1/sub-category-a/

$post->post_name becomes 'sub-category-a' the Template filters the query to show posts under that section.

Well sub-category-a, b, and c are going to be a "listings" page. It will pull in posts and link to the individual post. So obviously I am unable to create a page template the same way I made the Sub Category for these "specific posts" how would I go about reading the $post->post_name to filter each "sub-categories specific post" into its own page layout? single-post.php? This is where my understanding of WordPress begins to betray me. ;)

1 Answer

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Okay, first of all props on taking the time and mental concentration here to explain this :p

I have an upcoming deep dive on the template file hierarchy that will show this kind of stuff. However, I think that you need to slightly shift the way you are setting up your categories and what templates you're using.

Ideally, you would have a custom taxonomy (what categories are called for custom post types) for your custom post type and that is where the categories and nested categories will live.

Then you can use the template naming structure of taxonomy-taxonomy-slug.php (taxonomy-a.php, taxonomy-a-a.php, etc) for creating the actual templates for each category or sub category listing page. You may find you can do everything with one taxonomy.php page, since it will automatically figure out if you're displaying a main category or sub category. Or you can create custom templates for specific listing pages.

Check out this site here to see the flow from Archives > Custom Taxonomy: http://wphierarchy.com/

Hope this helps!

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Now, I do have both custom post and custom taxonomies set up with taxonomies relating to specific custom posts.

I think the upcoming deep dive will help sharpen my understanding of how to make the templates and custom post types flow together properly in any given situation. So, I can't wait to watch this deep dive.

Appreciate the link, that is a really neat helpful interactive hierarchy. :)