• Hello,

    Since the upgrade to 2.0, my if statement in the index.php is no longer functioning. The statement should only show posts that are not in category 4 on the home page. Here is the code. Thank you in advance for any help you can provide.

    <?php get_header(); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php if ( !(in_category(‘4’) && is_home()) ) { ?>

    <div class=”post”>
    <h2 class=”posttitle” id=”post-<?php the_ID(); ?>”>” rel=”bookmark” title=”<?php _e(‘Permanent link to’); ?> <?php the_title(); ?>”><?php the_title(); ?></h2>

    <p class=”postmeta”>
    <?php the_time(‘F j, Y’) ?> @ <?php the_time() ?>
    · <?php _e(‘Filed under’); ?> <?php the_category(‘, ‘) ?>
    <?php edit_post_link(__(‘Edit’), ‘ · ‘, ”); ?>

    <div class=”postentry”>
    <?php the_content(“Continue reading ” . the_title(”, ”, false)); ?>
    “>Comment on this post

    </div>

    <p class=”postfeedback”>
    ” rel=”bookmark” title=”<?php _e(‘Permanent link to’); ?> <?php the_title(); ?>” class=”permalink”><?php _e(‘Permalink’); ?>
    <?php comments_popup_link(__(‘Comments’), __(‘Comments (1)’), __(‘Comments (%)’), ‘commentslink’, __(‘Comments off’)); ?>

    <!–
    <?php trackback_rdf(); ?>
    –>

    </div>
    <?php } ?> <!– Close the if statement. –>

    <?php endwhile; ?>

    <?php posts_nav_link(‘ · ‘, __(‘Next entries »’), __(‘« Previous entries’)); ?>

    <?php else : ?>

    <h2><?php _e(‘Not Found’); ?></h2>

    <?php _e(‘Sorry, but the page you requested cannot be found.’); ?>

    <h3><?php _e(‘Search’); ?></h3>

    <?php include (TEMPLATEPATH . ‘/searchform.php’); ?>

    <?php endif; ?>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter afail

    (@afail)

    anyone?

    Thread Starter afail

    (@afail)

    still looking for ideas. seems that 2.0 dosen’t like the !(in_category(‘4’)

    On home page, you don’t want to show posts of category 4, is that it?

    <?php if (is_home() && !in_category(4)) { ?>

    Thread Starter afail

    (@afail)

    correct alpha,

    i tried <?php if (is_home() && !in_category(4)) { ?>

    it is still showing cat 4 posts. the exact code worked in 1.5, but since the 2.0 upgrade it’s not.

    Don’t post long code here, please!
    It is difficult to read and nobody really bothers to take a look at it. You can use http://pastebin.com or similar services – and post back with the URI.
    For posting small code snippets, please read carefully the instructions here below the text input area: the “backticks” usually are located on top-left of your keyboard, where ~ [tilde] is.

    That’s weird. Anyway, let’s just try another method.

    Delete the if-statement and the closing bracket.
    Add the following right before the Loop begins.

    <?php $wp_query->set('cat', '-4'); ?>
    <?php query_posts(''); ?>

    this works for me..im on WP 2.0
    hi guys found the solution
    its something like this

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <!– The following tests if the current post is in category 3. –>
    <!– If it is not, the code within The Loop is executed as normal. –>
    <!– If it is, nothing is done until the next post is processed. –>
    <?php if ( !(in_category(‘3’)) ) { ?>

    <div class=”post”>

    <h2>“><?php the_title(); ?></h2>

    <small><?php the_time(‘F jS, Y’); ?></small>

    <div class=”entry”>
    <?php the_content(); ?>
    </div>

    <p class=”postmetadata”>Posted in <?php the_category(‘, ‘); ?>
    </div> <!– closes the first div box –>

    <?php } ?> <!– Close the if statement. –>

    <?php endwhile; else: ?>
    Sorry, no posts matched your criteria.
    <?php endif; ?>

    i encountered a major problem with the code ive posted! It gets off all the posts related to the cat 4 (my e.g. cat) and will never show them!! does any one got a solution for this?

    i think if you use <?php if (is_home() && !in_category(4)) { ?>

    Then you have to provide a copy which enclosure that on an else statement following that.. because that says if its the home pages and post does not belong to cat 4 it will do the loop. What if its not the home or not category 4? This is the point where it does show up any posts related to cat 4!!
    therefore i think you should include an else <? php else {?> and copy paste the coding for showing posts..should work theorically..but i have to test and see

    just found a good solution which works !

    goto http://wordpress.org/support/topic/39698?replies=5

    it works really well!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Exclude Cat on Main Page in 2.0’ is closed to new replies.