• sixfootstudio

    (@sixfootstudio)


    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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • g3legacy

    (@g3legacy)

    Hi, try reading up on query_posts;

    https://codex.www.ads-software.com/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

    Thread Starter sixfootstudio

    (@sixfootstudio)

    Thanks Dan,

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

    Cheers!

    Thread Starter sixfootstudio

    (@sixfootstudio)

    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!

    g3legacy

    (@g3legacy)

    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

    Thread Starter sixfootstudio

    (@sixfootstudio)

    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 ??

    Thread Starter sixfootstudio

    (@sixfootstudio)

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

    g3legacy

    (@g3legacy)

    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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Exclude all categories except chosen categories from posts page’ is closed to new replies.