Forums

[resolved] Exclude category on sidebar (5 posts)

  1. Sumukha
    Member
    Posted 4 months ago #

    I have been reading some things in the Codex, but am not so php savy...

    I have a sidebar link
    <?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?>
    that needs to exclude one category.
    I see in the Codex
    query_posts('cat=-3');

    How do I combine these?

    Thanks

  2. Shane G
    Member
    Posted 4 months ago #

    Hi,

    Open wp-includes/widgets.php file at your local and edit it..you need to do it as these:

    Find this line:
    $d = $options[$number]['dropdown'] ? '1' : '0';

    Add this line below this line:
    $ex = "1,2,3";

    1,2,3 are the categories which you would like to exclude..

    Find this line:
    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);

    replace with:
    $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'exclude' => $ex );

    Save the file and upload it on the server again..you can replace the category ID with your desired one..

    Thanks,

    Shane G.

  3. mercime
    Member
    Posted 4 months ago #

    <?php wp_list_categories('show_count=1&exclude=10&title_li=<h2>Categories</h2>'); ?>
    exclude=10, 10 being the category ID number you want to exclude

    edit-I would not recommend edit of core WP files. In addition, when you upgrade your WP installation, such edit will be written over.

  4. Sumukha
    Member
    Posted 4 months ago #

    Thanks! (just wonder why I wasn't notified of your post)
    Can you also tell me how to have only one category displayed on the homepage?

  5. Sumukha
    Member
    Posted 4 months ago #

Reply

You must log in to post.

About this Topic