Display the submenus in the sidebar while in category
-
I need something like this:
I have a main menu at the top of the site
This menu has 5 options
One of these options has five sub-categories
And each of them more than 5 sub-categoriesWhen I click on one of these subcategories in the main menu at the top, I want a list of subcategories to this category in the left sidebar.
I do not want a full menu in left sidebar.
Only when entering the category, show the subcategories in the sidebar as a list.I thought about doing it this way:
In page.php, it calls the sidebar1 and sidebar2
I would create a sidebar3, unique to this when I entered in a category.
This would sidebar php code in a call to the submenus of this category.Anyone know guide me?
-
nobody?
In page.php, it calls the sidebar1 and sidebar2
Do you mean archive.php or category.php?i don’t know, is just a ideia
i don’t know the logic to do this
Try it with this in your sidebar.php
<?php if(is_category()) { // are we on a category or archive page $current_category = get_query_var('cat'); // the current category id $category= get_categories( 'include='.$current_category ); // if the parent category ID in the top navigation is the parent of the current category if($category[0]->category_parent == 3){ $child_categories= get_categories( 'child_of='.$current_category ); if(!empty($child_categories)){ foreach ( $child_categories as $child_cat ) { $categories[] = $child_cat->cat_ID; } $sub_children = implode(',', $categories); echo '<ul>'; wp_list_categories('include='.$sub_children); echo '</ul>'; } } } ?>
change the ID (3) to your main menu option ID with all the child categories.
$category[0]->category_parent == 3
In my tests shows nothing
I don’t know the ID of the category with subcategories, have tried several numbers.
Thanks so much for your help.
To find a categorie ID go to wp-admin > Posts > Categories and click on the category name of the top level category that is in your main menu at the top. The url of the page you are on will show what the category id is. eg
wp-admin/edit-tags.php?action=edit&taxonomy=category&post_type=post&tag_ID=14
means the category ID is 14ok my ID=1
Nothing happen =/
Blank screen in widget
Can you put the content of sidebar.php in the pastebin and link back to it
I put this code in sidebar1.php of my theme
Do you mean sidebar.php of my wordpress and not my theme?
Your theme’s sidebar.php
yes i put the code in sidebar1.php
you ever tested this code?
Yes I tested this code, It works on my testserver. But I put in sidebar.php. Please provide a link to your theme if possible?
i’m trying put this code in dinamic widget in sidebar…
is it why not this working?
my sidebar get dinamics widgets…
I don’t know dynamic widgets but I think that’s why it is not working.
well…this is the code in my sidebar1.php
Forget about dinamical widgets.<div class="layout-cell sidebar1"> <?php if(is_category()) { // are we on a category or archive page $current_category = get_query_var('cat'); // the current category id $category= get_categories( 'include='.$current_category ); // if the parent category ID in the top navigation is the parent of the current category if($category[0]->category_parent == 1){ $child_categories= get_categories( 'child_of='.$current_category ); if(!empty($child_categories)){ foreach ( $child_categories as $child_cat ) { $categories[] = $child_cat->cat_ID; } $sub_children = implode(',', $categories); echo '<ul>'; wp_list_categories('include='.$sub_children); echo '</ul>'; } } } ?> </div>
i’m, using this code..
I acess the top Menu e when i click in one sub-category ( this sub have other subs ) nothing show in my left sidebarscreen: http://img827.imageshack.us/img827/1816/categoriesz.png
- The topic ‘Display the submenus in the sidebar while in category’ is closed to new replies.