WordPress.org

Ready to get started?Download WordPress

Forums

Excluding some Category from Home Page (13 posts)

  1. orjense
    Member
    Posted 2 years ago #

    Newbie here!!!!!!!!!
    I need help and need it bad. I would like to know how I to exclude some Categories from home page.
    If I need to add some code, please give me the codes and tell me exactly where to insert the codes.
    But point and click will be awesome if any exist.
    Thanks in advance

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You will need to create a custom query in your theme's index.php template file. See:
    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query

  3. orjense
    Member
    Posted 2 years ago #

    Thanks for the help. I added the code below in my index.php and it didn't work for me, I'm sure I did something wrong. Is there any particular point
    at index.php that i need to insert the code?
    Thanks again

    if ( is_home() ) {
    query_posts( 'cat=-3,-4,-5,-6,-7,-8,-9' );
    }
    ?>

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Is there any particular point at index.php that i need to insert the code?

    Before the start of the Loop.

  5. orjense
    Member
    Posted 2 years ago #

    Esmi,
    Thank you so very much for all your help, really appreciate it.
    What does the start of the loop look like, what code should I look for to know where the loop start?
    Do forgive my kindergarten questions, I'm so new at this and need help here and there.

    Thank again.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try reading http://codex.wordpress.org/The_Loop It will pay dividends in the long run if you can learn how to use this all-important core element of any WordPress page.

  7. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    you could help us helping in more detail when you post the name of your theme.

    the loop usually starts with:
    if( have_posts() ) :
    or just with:
    while( have_posts() ) :
    or very similar.

    http://codex.wordpress.org/The_Loop

  8. orjense
    Member
    Posted 2 years ago #

    Alchmyth,
    I'm using AndroidPhone theme by NewWpThemes.com
    Regards

  9. orjense
    Member
    Posted 2 years ago #

    This is what my index.php look like

    [Code moderated as per the Forum Rules. Please use the pastebin]

  10. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    have a look into index.php;

    line 6 ( <?php if (have_posts()) : ?> ) is the start of the loop;

    add your code just before that line:

    <?php
    if ( is_home() ) {
    query_posts( 'cat=-3,-4,-5,-6,-7,-8,-9' );
    }
    ?>

    to avoid problems with pagination, expand the code, following the example from:
    http://codex.wordpress.org/Function_Reference/query_posts#Usage_Note:

    <?php
    if ( is_home() ) {
    global $query_string;
    query_posts( $query_string.'&cat=-3,-4,-5,-6,-7,-8,-9' );
    }
    ?>
  11. Sam
    Member
    Posted 2 years ago #

    Oh wow. I think this is my situation exactly.

    I am using a plugin to display printable recipes (Easy Recipe) that requires each recipe to be a separate post. I also have a straightforward blog on the site, and I don't want the recipe posts to show on the "Blog" page as posts.
    I have 2 categories: Recipes and Blog. I assume that there is a relatively easy way to exclude the Recipes category from displaying in the Blog page.

    If my "blog" is not the home page, do I still add the code to the index.php or to single.php, or somewhere else?
    Thanks so much...

  12. Sam
    Member
    Posted 2 years ago #

    Got it! Thanks esmi.

  13. orjense
    Member
    Posted 2 years ago #

    alchymyth-
    Thanks a lot for pointing me to the right direction. Everything works like a charm. Thank.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags