Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is my home page code

here is a feature post section, i want to exclude post by a category 'Collage' in this section ...

<?php 
$count = 1;
if (have_posts()) : while (have_posts()) : the_post(); if($count == 1) : ?>


<div id="featurd_post">
<div class="ftrd_image">
<?php woo_get_image('image',455,245,' '.$GLOBALS['align']); ?>  </div>
<div class="fix"></div>
<div class="ftrd_entry">
<h2 class="title">
<a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php   the_title(); ?></a> 
</h2>
<p class="fetrd_entry"><?php dynamic_excerpt(400); ?></p>
<a href="#" title="" class="read_more">(<?php _e('&#2310;&#2327;&#2375; 
&#2346;&#2338;&#2375; ', 'shreshthbharat'); ?>)</a>
</div></div>     
<?php else : ?>

  <--- Rest of post goes here --- > 

<div class="box"><div class="post">
<h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="">
<?php the_title(); ?></a></h2>
share|improve this question
    
how are the 'featured' posts defined? is there a query before the first line of your posted section? if so, can you please post that as well? –  Michael Nov 6 '11 at 17:42
    
no this is just a simple section '#featurd_post' i mean it's first post different from rest of all post, i want to exclude 'collage' category posts in this section. –  user8503 Nov 6 '11 at 17:46

2 Answers 2

To exclude a category you'll need to modify the query that's running. Do this using the query_posts() function: http://codex.wordpress.org/Function_Reference/query_posts

First, you'll need to get the ID of the category you want to exclude:

$exclude_category = get_term_by('name', 'collage', 'category');

Then you'll need add the category exclusion to the query, and pass the new query to query_posts:

global $wp_query;
$args = array_merge( $wp_query->query, array( 'category__not_in' => array( $exclude_category) ) );
query_posts( $args );

Put all this right at the top of the script, just before the loop.

Hope that works for you!

share|improve this answer

Try this may be work.. I didnt wrote it but found on wordpress website.

 <?php query_posts($query_string . '&cat=-3,-8'); ?>
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <div class="post">

 <!-- Display the Title as a link to the Post's permalink. -->
 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

 <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

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

  <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
 </div> <!-- closes the first div box -->

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

for more details you can check this link http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.