• Resolved perpetualjon

    (@perpetualjon)


    I’m trying to hide all posts except one category on the main page. My problem is that the index.php code is also used for calling all my pages as well. I’m currently using the following code…

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if (in_category(‘5’)&& is_home()) continue; ?>
    <?php if (in_category(‘6’)&& is_home()) continue; ?>

    My problem is that each new post category means that I have to make another line to exclude it from the home page. I’d rather have an “opt in” function like this one I tried before…

    <?php query_posts(‘cat=12’); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    The problem with coding this way (although I do get the correct result on the home page) is that EVERY page I attempt to view now only shows POSTS of this category and not the PAGES since I have not modified the main index page that all the subsequent pages are made from. Is there a way to exclude all but one category of posts from the home page and still manage to render other page views on different pages and not have the same result?

Viewing 4 replies - 1 through 4 (of 4 total)
  • use query_posts('showposts=X&cat=Y')
    you may also want to clean the query with
    <?php rewind_posts(); ?>

    Thread Starter perpetualjon

    (@perpetualjon)

    Ok, that just got me the same result as the query_posts earlier function. Or am I implementing the code incorrectly? Here’s what I did:

    <?php query_posts(‘showposts=175&cat=16’); ?>
    <?php rewind_posts(); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    I think my main problem is that I have a “main index template” but no “page template” in the theme I’m using. Am I simply out of luck here or is there a way to successfully “opt in” posts and still render pages? I’m going to try and contact the theme creator and find out if they have a version that does use a page template as well…

    Thanks everyone for all your help so far.

    Thread Starter perpetualjon

    (@perpetualjon)

    Well, now that I’m using 2.7, I realized that there is a feature (maybe it’s been there all along) but it allows me to display a chosen Page on the initial view of the site if I chose. This solves my problem of only showing a single category on the main index template code. So much easier than the route I was taking!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Only show posts from one category (but show all pages)’ is closed to new replies.