Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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>';
        }}}
    ?>
    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)

    may i ask the flaws in using query_posts() in 2nd loop
    compared to wp_query or get_posts?

    Thread Starter vicoftw

    (@vicoftw)

    thanks i will look into it

Viewing 4 replies - 1 through 4 (of 4 total)