Support » Plugins » Hacks » stripping out categories

  • I’ve been combing through various methods for displaying the category within a single post as a footer. However, I am using categories to control various custom loops and I want to eliminate one particular category from display in the footer.

    I am currently just using the_category() within the single.php page, but I have also experimented with wp_list_categories(), as it offers the ‘exclude’ $arg. However, this displays a list of ALL categories, rather than those that are associated with this PARTICULAR post. I’m not strong enough of a PHP coder to limit the return within wp_list_categories() without tying knots with a bunch of conditionals like in_category() and is_category().

    The default function of the_category() is perfectly suitable for me, (i.e. links and standard delimiters) but I want to strip out just ONE specific category, as it is only used to manage multiple loops and I don’t want it displayed with the rest of the categories.

    Just wondering if anyone has run into anything like this. Thanks a bunch.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Adrian Wong


    Hi dls4,

    I’m not really sure what your problem is, but am guessing that it may be an issue with how you organise your categories rather than using the category functions.

    One way of not displaying the specific category, rather than using exclude, try using only include to display the categories you want to show for wp_list_categories().

    Example of displaying only category 3,4 and 5 as a list view:
    <?php wp_list_categories('include=3,4,5&title_li='); ?>

    Or dump them under a parent category and display the children:
    <?php wp_list_categories('child_of=1&title_li='); ?>

    Hope these helps 🙂

    Thanks for the response. I realize the post might have been a bit confusing. I am running a few custom wp_query loops to control a grid of thumbnails containing custom key fields in the posts. To split a group that will always remain on the top, I am using the category to do this. Looks basically like this:

    // Query for toprow only
    $new_querytop = new WP_Query();
    $new_querytop->query( 'showposts=3&category_name=toprow&paged='.$paged );
    //Query for remaining rows
    $new_query = new WP_Query();
    $new_query->query( 'showposts=3&category_name=recentprojects&paged='.$paged );

    Since I am only using the category “toprow” to strip out specific posts, I don’t want it to display in the footer.

    I think I will take your advice and dump the ones for display into a parent category and use the child_of to handle them, since they would all fall into the same parent group anyhow.

    Thanks again for the input.

    Adrian Wong


    I usually use category number as it is more consistent than category name.
    Just a note if you’re using the query function, always remember to add the <?php wp_reset_query(); ?> at the end of the query to rest it, otherwise the post display may not be what you wanted if there are more than 1 query function.

    Cheers 🙂

    I was actually trying to use the category numbers, but I couldn’t find anywhere in the admin to identify them. I’m sure that I am missing something obvious–the post ID is displayed directly at the top of the post editor, but where is the cat ID?

    Will definitely implement the reset. Thanks for the advice. It has worked pretty well without it so far, but I am usually only running two or so loops. This particular site has 4 running on the home page, so it will be pretty good to rest it.

    Thanks again for the input. Great forum, great software, great users.

    One quick question, where should I insert that reset? After the trackback?

    Adrian Wong


    You should place the reset after the loop and function you’ve called from the query has been made – just before the next query…

    For the category numbers, I usually go to my Edit Category page and click on the category I want to target, and look for the category&tag_ID=1 from the url link.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘stripping out categories’ is closed to new replies.