Forums

Exclude all categories except chosen categories from posts page (8 posts)

  1. sixfootstudio
    Member
    Posted 1 year ago #

    Hi,

    My home page is a product feature page which uses a number of posts with specific posts and categories attached to those posts.

    The problem I am having now that I have finished the product feature page is that any new posts I add to WP will appear on this product feature page which I am trying to prevent.

    Is there a way to exclude all other categories from this main product feature page?

  2. g3legacy
    Member
    Posted 1 year ago #

    Hi, try reading up on query_posts;

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

    You just put your query above your loop. You could either exclude certain categories or include certain categories. I'd go for include as you may keep adding other categories elsewhere....

    Dan

  3. sixfootstudio
    Member
    Posted 1 year ago #

    Thanks Dan,

    I am going to have a look into this now and let you know how I get on :)

    Cheers!

  4. sixfootstudio
    Member
    Posted 1 year ago #

    Hi Guys.

    I've tried this now and when I run the page, all I get is
    query_posts( 'cat=-1' ); at every iteration of the posts.

    I've added the query_posts(); just before the loop as suggested in that post but think I may be missing something.

    Thanks!

  5. g3legacy
    Member
    Posted 1 year ago #

    Hi, can I have a link to the page? It would also help if you put your php code for the loop on here.

    Dan

  6. sixfootstudio
    Member
    Posted 1 year ago #

    Hi Dan,

    The site is not live yet but here's the snippet of code for the loop.

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    query_posts( 'cat=-1' );
    <div <?php post_class(); ?>>
    <h2>"><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php if ( !is_singular() && get_the_title() == '' ) : ?>
    <!--">(more...)-->
    <?php endif; ?>
    <?php if ( is_singular() ) : ?>
    <div class="pagination"><?php wp_link_pages(); ?></div>
    <?php endif; ?>
    <div class="clear"> </div>
    </div><!-- post_class() -->
    <?php if ( is_singular() ) : ?>
    <div class="meta">
    </div><!-- meta -->
    <?php comments_template(); ?>
    <?php endif; ?>
    <?php endwhile; else: ?>
    <div class="hentry"><h2>Sorry, the page you requested cannot be found</h2></div>
    <?php endif; ?>
    <?php if ( is_active_sidebar( 'widgets' ) ) : ?>
    <div class="widgets"><?php dynamic_sidebar( 'widgets' ); ?></div>
    <?php endif; ?>
    <?php if ( is_singular() || is_404() ) : ?>

    <?php else : ?>
    <div class="left"><?php next_posts_link( '« Older posts' ); ?></div>
    <div class="right"><?php previous_posts_link( 'Newer posts »' ); ?></div>
    <?php $key_1_values = get_post_meta($post->ID, 'buy-now','true'); ?>

    <?php endif; ?>

    Thanks ;)

  7. sixfootstudio
    Member
    Posted 1 year ago #

    Managed to figure it out! Thanks for the help Dan!

  8. g3legacy
    Member
    Posted 1 year ago #

    No Problem, that code you pasted has some syntax errors so make sure you double check what you have incase they are still there... I've searched for ages before now, only to find I missed a colon or something!

    Dan

Topic Closed

This topic has been closed to new replies.

About this Topic