WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] exclude category from the home page posts (8 posts)

  1. ottanio
    Member
    Posted 1 year ago #

    i have a template download from http://www.dessign.com
    this part of the index page exclude the category ('illustration') from the hom page posts.
    <?php get_header(); ?>
    <div class="home_big_post_cont">
    <?php
    $exclude_arr = array();
    $category_ID = get_category_id('illustration');
    $args = array(
    'post_type' => 'post',
    'cat' => '-' . $category_ID,
    'posts_per_page' => 3
    );
    query_posts($args);
    $x = 0;
    while (have_posts()) : the_post(); ?>

    How can I exclude also other categories? ex. ('news')

  2. TurboLobster
    Member
    Posted 1 year ago #

    There is a plugin that will do it. I think it is called ultimate category excluder or something like that. search for it in you install plugin area. I would look it up for you but I'm on my cell phone so hard to do.

  3. ottanio
    Member
    Posted 1 year ago #

    i will try thanks

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    without plugin:

    <?php
    $exclude_arr = array();
    $category_ID_1 = get_category_id('illustration');
    $category_ID_2 = get_category_id('news');
    $args = array(
    'post_type' => 'post',
    'category__not_in' => array( $category_ID_1, $category_ID_2 ),
    'posts_per_page' => 3
    );
  5. LastForOne
    Member
    Posted 1 year ago #

    or you can simply find the id's of both categories from the wordpress dashboard and exclude them like:
    'cat' => '-1,-2';
    more @ #Exclude_Categories_From_Your_Home_Page

    Peace,
    LastForOne

  6. TurboLobster
    Member
    Posted 1 year ago #

    I agree coding it out is lighter but if you add more categories later on you don't have to keep fiddling with the code when using the plugin. With the plugin you can check box the category out when adding a new category.

  7. ottanio
    Member
    Posted 1 year ago #

    i installed the plugin, works... Great!!!!
    the code doesn't work (alchymyth), i see all categories, i don't know why.
    Thanks for the help
    Little question:
    i have in the home: last projects (6posts), last news (three posts), random projects (three posts).
    is it possible exlude the categories (illustrator,news) from the first 6 post in home, but not exclude these from the random posts?
    Exclude for a part of the home....
    maybe is possible change the code of the plugin.
    thanks a lot to all.

  8. ottanio
    Member
    Posted 1 year ago #

    i made a mistake the code (alchymyth) works
    thanks to all

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags