Originally posted by QuickRon
View Post
Announcement
Collapse
No announcement yet.
Exclude specific categories from category tree
Collapse
X
-
Hi Nick.
Awesome!! Thank you so much for sharing this with us! It works perfectly!
Thank you!!
Ron
Leave a comment:
-
Although this will require some initial coding changes, You shouldn't have to deal with code once it is set up properly.
You can achieve what you are looking for by using a Custom Category Field.
Custom Field Set Up- Navigate to Settings > Utilities > Custom Fields
- Click "New Custom Field"
- Use the following settings
- Type: Category Field
- Code: exclude_cat_cattree
- Name: Exclude From Cattree
- Field Type: Checkbox
- Additional Information: check this box to exclude category from category tree (this is not required but can be a helpful internal hint for you or your employees)
- Click Add
- Navigate to the Category you want to exclude and click the Category Name
- Go to the "Custom Fields" Tab and Check the box for the new "Exclude From Cattree" custom field you just created
- Click Update
- Repeat steps 4-6 to exclude as many Categories as you want
- Navigate to User Interface > Global Settings and scroll to the Category Tree Template
- Below the Template is a Section Called "Custom Fields"
- In the left hand box there is a list of all of your Custom Category Fields for your store
- Find the "Exclude From Cattree" custom field and click on it so it is highlighted in blue
- Click the "Select" button and you will see that selected custom field now appears in the right hand box
- Wrap your category tree conditionals for the links with the conditional code in red. Make sure all category tree conditionals are within this conditional and make sure the conditional is inside the foreach iterator
Code:
<mvt:foreach array="cattree_categories" iterator="cattree_category"> <mvt:if expr="l.settings:cattree_category:customfield_values:customfields:exclude_cat_cattree NE '1'"> <mvt:if expr="l.settings:cattree_category:level EQ 1"> <mvt:if expr="NOT ISNULL l.settings:category:id AND l.settings:category:id EQ l.settings:cattree_category:id"> <li class="level-&mvte:cattree_category:level;"><a class="bold current-item" href="&mvte:cattree_category:link;">&mvt:cattree_category:name;</a></li> <mvt:else> <li class="level-&mvte:cattree_category:level;"><a href="&mvte:cattree_category:link;">&mvt:cattree_c ategory:name;</a></li> </mvt:if> <mvt:elseif expr="l.settings:cattree_category:level EQ 2"> <mvt:if expr="NOT ISNULL l.settings:category:id AND l.settings:category:id EQ l.settings:cattree_category:id"> <li class="level-&mvte:cattree_category:level;"><a class="bold current-item" href="&mvte:cattree_category:link;">&mvt:cattree_category:name;</a></li> <mvt:else> <li class="level-&mvte:cattree_category:level;"><a href="&mvte:cattree_category:link;">&mvt:cattree_c ategory:name;</a></li> </mvt:if> <mvt:else> <mvt:if expr="NOT ISNULL l.settings:category:id AND l.settings:category:id EQ l.settings:cattree_category:id"> <li class="level-&mvte:cattree_category:level;"><a class="bold current-item" href="&mvte:cattree_category:link;">&mvt:cattree_category:name;</a></li> <mvt:else> <li class="level-&mvte:cattree_category:level;"><a href="&mvte:cattree_category:link;">&mvt:cattree_category:name;</a></li> </mvt:if> </mvt:if> </mvt:if> </mvt:foreach>
- Click Update
In Miva the value of a custom field checkbox is 1 if it is checked.
So what that conditional is doing is checking to see if the value of the exclude_cat_cattree custom field does NOT EQUAL 1.
So if it does NOT EQUAL 1 (exclude_cat_cattree checkbox IS NOT checked), then it will display the category link in the category tree.
If it does equal 1 (exclude_cat_cattree checkbox IS checked), then it will not show the categgory link in the category tree.
I tested this in our store's Developer Template Branch and it does indeed work.
Hopefully this helps you and anyone else looking for the same functionality.
Cheers,
NickLast edited by SidFeyDesigns; 09-08-22, 02:32 PM.
Leave a comment:
-
Would a ReadyTheme Navigation Set work here? It would replace the default category tree and you get to manually assign/unassign the what categories you want to show up.
https://docs.miva.com/videos/readytheme-nav-sets
Leave a comment:
-
Right .... and that's why I created this post under Dream Features ... for Miva to provide an easier way (ie without modifying code) to exclude categories/sub-categories from the category tree. Similar to excluding Navigation Items in a Ready Theme Navigation Set. We can dream, can't we? :-)
Leave a comment:
-
Then you'd need to modify the code in the category tree template. How to do that would depend on what you actually wanted to display in that area of your site when you are looking at the sub-categories.
Leave a comment:
-
The parent category is set to inactive and does not show up in the category tree. But the active sub-category does appear in the category tree on that sub-category page only.
Leave a comment:
-
Thank you, Bruce!
That seems to work. The category will appear in the category tree while on that category page, but I don't think that will be a problem.
Leave a comment:
-
Maybe this doesn't do what you want, but you can always just assign them to a top level category that is set to inactive.
Leave a comment:
-
Exclude specific categories from category tree
An easy way to exclude specific categories from appearing in the category tree.
Please.
Thank you.Tags: None
Leave a comment: