Forums

Output of subcategories and subpages at the sidebar (1 post)

  1. klarabella
    Member
    Posted 2 years ago #

    Hello everybody,
    I'm sorry if my request sounds a little confusing.

    I want to use WordPress more like a CMS and melt category and page navigation a bit. At the moment my blog is showing one horizontal main navigation menu at the top with the following links:
    Home | Top Cat 1 | Top Cat 2 | Page 1 | Page 2
    To make this work I'm currently using the blog-in-blog plugin which links categories to pages. The home page is a static page. All these links are the top level and always shown.

    Now I wanted to show at the top of the sidebar

    + when viewing a subcategory or post inside of Top Cat 1
    - Sub Cat 1.1
    - Sub Cat 1.2
    - Sub Cat 1.3
    -- Sub Cat 1.3.1
    - Sub Cat 1.4

    + when viewing a subcategory or post inside of Top Cat 2
    - Sub Cat 2.1
    - Sub Cat 2.2
    -- Sub Cat 2.2.1
    - Sub Cat 2.3
    - Sub Cat 2.4

    + when viewing a Page 1 or a subpage of it
    -Sub Page 1.1
    -- Sub Page 1.1.2
    - Sub Page 1.2

    I already tried the information given here by t31os_ and snatched a bit of code. It does what it should on the categories but doesn't work when viewing a single post and of course the part for the pages is missing.

    <?php
    if(is_category() || is_single()) {
    
            $breakpoint = 0;
            $subcategories = get_terms('category', 'parent='.get_query_var('cat'));
            $thiscat = get_term(get_query_var('cat'),'category');
    
            while(empty($subcategories)) {
                    $subcategories = get_terms('category', 'parent='.$thiscat->parent.'');
                    $breakpoint++;
                    if($breakpoint > 10) break; // Avoid infinite loop (you never know)
            }
    
            $items='';
            foreach($subcategories as $subcat) {
                    if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';
                    $items .= '
                    <li class="cat-item cat-item-'.$subcat->term_id.$current.'">
                            <a href="'.get_category_link( $subcat->term_id ).'" title="'.$subcat->description.'">'.$subcat->name.'</a>
                    </li>';
            }
    
            $dyntitle = get_cat_name( $subcat->parent );
            $wrapcat .= '
            <div class="widget categories widget-categories">
            <div class="widget-inside">
            <h3 class="widget-title">'.$dyntitle.'</h3>
            <ul class="categories">'.$items.'
            </ul></div></div>';
            echo "$wrapcat";
    }
    ?>

    I guess this is too complicated for what I want to do?
    I'd be so happy if somebody could help me. Thank you very much in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic