Could you help me work out how best to display category and sub category content please? I would like to separate out the content as follows:
1. Top level category
List of items assigned to just the top level category
1.1 Sub category
List of items within the first sub category
1.2 Sub category
List of items within the second sub category
You can see my progress here: hidden link
The first two items in the list are top level, then the second two are each in a sub category. Can I separate them out into separate lists?
Hi, I take it in this case "advertisements" is a top-level category. I also assume that you want to include this display on all the term archive pages for this research-category taxonomy, not just the advertisements term archive. What should happen if someone visits a subcategory archive? Is the top level still "advertisements", or is the top level now the subcategory? Will there ever be more than one level of subcategory, like a sub-sub-category or sub-sub-sub-category?
Yes, that's right "advertisements" is the top-level. I've created a WordPress Archive for the top level which displays the contents of that category.
Each top level category will have the same display.
That's a good question about how the subcategories will work. Initially I'm going on the basis that we will display the contents on the top level. But it could be that we have a list of the subcategories which you click on to be taken to a page with the same layout as the top level. Is either of the two options easier to achieve? Quite happy to go for the line of least resistance.
I'm going to limit it to one level of subcategory. I think it will be too complicated to add any deeper levels.
Wordpress will create an archive URL for all the terms in a taxonomy, regardless of the hierarchy. So if someone types the URL in manually, they will be shown an archive even if you don't create links to that archive. Toolset's WordPress Archives will be applied to all hierarchical levels of a taxonomy, by default, unless you add some custom code. So I guess the easiest approach is to create one WordPress Archive and let that be applied to all hierarchical levels.
In that WordPress Archive, you will include a View of terms, filtered by term ID, set by a shortcode attribute. Pass in the current archive taxonomy term ID using the wpv-taxonomy-archive shortcode:
Insert the term name or something similar in the loop, to produce the top-level term list. Inside that View, just after the term name, you will nest another View of terms, filtered by term parent, set by the current loop. This will produce the child terms list, so insert the term name or something similar in the loop.
Inside each of these term Views, you'll insert a View of posts filtered by term. Let's see if we can get that far, then I can share some custom code that will help filter out duplicates.
I've got a bit further with this. I've created a view which lists the sub categories of the parent category for the page you are on, which you can see on the advertisements page: hidden link
What I'd like to do now is adjust the list of items for the partent category so they don't display sub cat items. In this example it's currently showing:
Advertising in Lyme Regis 1930
Somewhere to stay in Lyme Regis
Sub Category Download 1
Sub Category Download 2
The top two are directly in the advertisements category so I would like those to display, but the bottom two are in sub categories. Can you help me filter them out please?
You can see I have limited this filter to run only on View #70. I believe this is the top-level View, but please correct that if I'm wrong. Then add this code to your child theme's functions.php file, or to a new code snippet in Toolset > Settings > Custom Code.
Hi Christian, sorry for not replying sooner, I was travelling all day yesterday so haven't had a chance to try it out yet. I'll be back in touch as soon as I'm caught up.
I really appreciate your help with this!
Cheers, Emily
I've added the code to my functions but it hasn't made any difference: hidden link
Is it because the first list of items is generated in the WP Archive rather than by a view? I'm happy to give you access to the site if it would be easier for you to have a look.
Thanks for your continued help!
Best wishes, Emily
As Christian is currently on vacation at the moment, I will be looking after his queue.
I see that christian specified a view id of 70 in the code. Is your view ID 70 ? If not then you will need to change the ID to the ID of your view in order to get it to work.
Also where did you add the snippet? If it is in our Toolset custom code section then you need to click on the activate button in order for the snippet to work.
So what I've got is this: hidden link
Looking at this list:
Advertising in Lyme Regis 1930
Somewhere to stay in Lyme Regis
Sub Category Download 1
Sub Category Download 2
I want to filter out the bottom two as they belong to the sub categories.
The list is generated by the WordPress Archive (which has an id 0f 70).
I've added the snippet to functions.php for the theme - it's a custom theme so I've put it directly into the parent theme functions.