Support » Themes and Templates » [help] how to show a REAL single category ?

  • Resolved c_a_k_r_a


    Case :
    post 1, category “banana”
    post 2, category “banana” and “apple”
    post 3, category “banana” and “manggo”
    post 4, category “banana”
    post 5, category “banana”, “apple” and “manggo”

    Default result in “banana” category page ( http://my_site/category/banana/ ) will show post 1,2,3,4 and 5.

    Primary Question :
    How do I show only post 1 and 4 (it’s mean the post which have only single category) in “banana” category page ?
    1) condition is_category() didn’t work for this case because is_category('banana') will always show post 1 – 5.
    2) query query_posts("cat=1"); or query_posts('category_name=banana'); has the same result too.

    Secondary Question :
    May be my primary question will solved if somebody can tell me how do I check if post have only pure one (single) category or more in query before push it to the loop ?

    I appreciate U’r help and thx before..

Viewing 3 replies - 1 through 3 (of 3 total)
  • Somebody help… 🙁

    Try something like this inside the loop but before any of the post information:

    $category_array = get_the_category();
    if ( count( $category_array ) > 1 ) { continue; }

    Another option is to exclude all the other categories using query posts, so before the loop:

    //get the requested category
    $cat_id = array( get_query_var('cat') );
    //get all the category ids
    $cat_ids = get_all_category_ids();
    //remove the one we have from the one we want
    $cat_result_array = array_diff( $cat_ids, $cat_id );
    //create a new query to remove what we don't need
    query_posts( $query_string . "&cat=" . implode( ',-' , $cat_result_array ) );

    There is probably a much easier way to do it, but these are the ones that spring to mind.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[help] how to show a REAL single category ?’ is closed to new replies.