WordPress.org

Ready to get started?Download WordPress

Forums

Getting a dynamic sidebar nav for categories (1 post)

  1. Icethrill
    Member
    Posted 4 years ago #

    At the moment I have created a very neat page navigation. The function manages the sidebar page navigation, here what its does briefly explained:

    • It checks if a page has children, if it does not have children. Do nothing.
    • If the page has children. Display only those children in the navigation. Not the top parent.
    • It manages both child and grandchild relations, even on a grandchild page the navigation outputs depends on what the top parent is.
    • The top parent name should always be displayed as a headline, but only if the top parent has children
    • This works amazingly well with a top navigation that only shows the top depth.

    At the moment, this only works with pages. I want the exact functionality for categories. I have tried, but without success.

    Here is the code for my sidebar page navigation:

    if (!is_front_page()) {
    			if(!$post->post_parent){
    				$parent_title = get_the_title($post->post_parent);
    				$children = wp_list_pages("title_li=<h2>" . $parent_title . "</h2>&child_of=".$post->ID."&echo=0");
    			}else{
    				$parent_title = get_the_title($post->post_parent);
    				$children = wp_list_pages("title_li=<h2>" . $parent_title . "</h2>&child_of=".$post->post_parent."&echo=0");
    
    				if($post->ancestors) {
    					$parent_title = get_the_title($post->post_parent);
    					$ancestors = end($post->ancestors);
    					$children = wp_list_pages("title_li=<h2>" . $parent_title . "</h2>&child_of=".$ancestors."&echo=0");
    				}
    			}
    		}
    		?>
    		<?php if($children){ ?>
    		<div id="primary" class="aside main-aside">
    			<ul class="xoxo sidebar-item">
    				<?php echo $children; ?>
    			</ul>
    	</div><!-- #primary .aside -->
    <?php } ?>

    I tried using get_category() function but without any good results. Anyone got any tips, ideas for usable functions? I want to make it as dynamic as possible! Any tips appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic