• Resolved Alyson

    (@rn2web)


    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-categories

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

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter Alyson

    (@rn2web)

    nobody?

    Moderator keesiemeijer

    (@keesiemeijer)

    In page.php, it calls the sidebar1 and sidebar2
    Do you mean archive.php or category.php?

    Thread Starter Alyson

    (@rn2web)

    i don’t know, is just a ideia

    i don’t know the logic to do this

    Moderator keesiemeijer

    (@keesiemeijer)

    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

    Thread Starter Alyson

    (@rn2web)

    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.

    Moderator keesiemeijer

    (@keesiemeijer)

    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 14

    Thread Starter Alyson

    (@rn2web)

    ok my ID=1

    Nothing happen =/

    Blank screen in widget

    Moderator keesiemeijer

    (@keesiemeijer)

    Can you put the content of sidebar.php in the pastebin and link back to it

    Thread Starter Alyson

    (@rn2web)

    I put this code in sidebar1.php of my theme

    Do you mean sidebar.php of my wordpress and not my theme?

    Moderator keesiemeijer

    (@keesiemeijer)

    Your theme’s sidebar.php

    Thread Starter Alyson

    (@rn2web)

    yes i put the code in sidebar1.php

    you ever tested this code?

    Moderator keesiemeijer

    (@keesiemeijer)

    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?

    Thread Starter Alyson

    (@rn2web)

    i’m trying put this code in dinamic widget in sidebar…

    is it why not this working?

    my sidebar get dinamics widgets…

    Moderator keesiemeijer

    (@keesiemeijer)

    I don’t know dynamic widgets but I think that’s why it is not working.

    Thread Starter Alyson

    (@rn2web)

    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 sidebar

    screen: http://img827.imageshack.us/img827/1816/categoriesz.png

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Display the submenus in the sidebar while in category’ is closed to new replies.