• Hi there I am abit of a lost right now on the direction to approach
    this problem

    Main nav will be like this

    Home
    Category1 ->
    Sub Category
    Sub Category
    Post of Category1 (Not subcategory posts)
    Post of Category1 (Not subcategory posts)
    Category2 ->
    Sub Category
    Sub Category
    Post of Category2 (Not subcategory posts)
    Category3

    something along side this structure.
    what I current have is

    Home
    Category1 ->
    Post of Category1
    Post of Subcategory1
    Sub Category ->
    Post of Subcategory1
    Category2
    Category3

    Below is the code.

    <?php	$args=array(
    	'orderby' => 'name',
    	'order' => 'ASC',);
    	$categories=get_categories($args);
    	foreach($categories as $category) {
    	if ( $category->name != "article"){
        echo '<li><a href="' . get_category_link( $category->term_id ) . '" class="title"  title="' . $category->name . '" >' . $category->name . '</a> <ul>';
    	$cat_query = new WP_Query('category_name='.$category->slug );
    	while ($cat_query->have_posts()) : $cat_query->the_post();
    	echo '<li><a href="' . get_permalink($post->ID) . '" title="' . the_title_attribute('echo=0') .'" >' . the_title('','',false) . '</a></li>';
    	endwhile; wp_reset_postdata();
    	echo '</ul> </li>';
        }}
    ?>

    tried wp list categories but it lacks the posts that are made
    in the top level of the category.

    solutions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter vicoftw

    (@vicoftw)

    only 1 last thing I am getting stuck on.
    which is removing the Sub category Posts.

    while ($cat_query->have_posts()) : $cat_query->the_post();
    	$flag=1;
    	foreach (get_the_category( $post->ID ) as $cat ){
    	if($category->name != $cat){
    	$flag=0;
    	}}
    	if ($flag == 1 ) {
    	echo '<li><a href="' . get_permalink($post->ID) . '" title="' . the_title_attribute('echo=0') .'" >' . the_title('','',false) . '</a></li>';
    	}
    	endwhile; wp_reset_postdata();

    i know my code is like everywhere…
    right now the flag is always changed to 0.
    any suggestion on how to do this?

    Thread Starter vicoftw

    (@vicoftw)

    got it done.. didn’t pay attention to the return value of get_the_category ??

    final code… (anyway to clean it up?)
    way too much of a mess

    <?php	$args=array(
    	'orderby' => 'name',
    	'order' => 'ASC',);
    	$categories=get_categories($args);
    	foreach($categories as $category) {
    	if ( $category->name != "article"){ if ( $category->category_parent == 0){
        echo '<li><a href="' . get_category_link( $category->term_id ) . '" class="title"  title="' . $category->name . '" >' . $category->name . '</a> <ul>';
    	$cat_query = new WP_Query('cat='.$category->term_id );
    	foreach($categories as $subcat){
    	if ( $subcat->category_parent == $category->term_id ) {
    	echo '<li><a href="' . get_category_link( $subcat->term_id ) . '" title="' . $subcat->name . '" >' . $subcat->name . '</a> </li>';
    	}}
    	while ($cat_query->have_posts()) : $cat_query->the_post();
    	$flag=1;
    	foreach (get_the_category( $post->ID ) as $cat ){
    	if($cat->category_parent !=0){
    	$flag=0;
    	}}
    	if ($flag == 1 ) {
    	echo '<li><a href="' . get_permalink($post->ID) . '" title="' . the_title_attribute('echo=0') .'" >' . the_title('','',false) . '</a></li>';
    	}
    	endwhile; wp_reset_postdata();
    	echo '</ul> </li>';
        }}}
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Top Nav Mutli Level’ is closed to new replies.