WordPress.org

Ready to get started?Download WordPress

Forums

Exclude category from index page (5 posts)

  1. baszer
    Member
    Posted 1 year ago #

    Hello,

    I use a static homepage and another page for my news. Now I want to exclude a certain category, but code below is not working. What do I do wrong?

    <?php query_posts($query_string . '&cat=-14'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    14 is the category which I want to remove. (Is it also possible to add a slug?)

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters

    try adding global $query_string; to the code

    Is it also possible to add a slug?

    not directly, but you can get the cat id from a slug with:

    http://codex.wordpress.org/Function_Reference/get_category_by_slug

  3. baszer
    Member
    Posted 1 year ago #

    <?php global $query_string; query_posts($query_string . '&cat=-14'); ?>

    like this?

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    why are you asking?

    have you tried it?
    did it work?

  5. baszer
    Member
    Posted 1 year ago #

    why are you asking?

    because it did not work ;)

Topic Closed

This topic has been closed to new replies.

About this Topic