0

I'm trying to exclude a category because I have a post that i have in multiple post. How do I like for example I have a post in the categories lastest news and pictures but I want to exclude latest news and show only the pictures name. I tried using $category = get_the_category(); echo $category[0]->cat_name; but that's no help.

any help is appreciated.

3 Answers 3

1
$recentPosts = new WP_Query(); $recentPosts->query('cat=-3'); //-3 makes sure it shows all categories except for ID number 3
        while ($recentPosts->have_posts()) : $recentPosts->the_post(); 

the_title();
the_content();        

endwhile;

Would something like this Work?

0
1

actually I fingered it out this code worked.

<?php
//edit below for categories you want excluded
$exclude = array("Latest News", "Uncategorized");
//how do you want the list separated? just a space is okay
$separator = " | ";
//don't edit below here!
$new_the_category = '';
foreach((get_the_category()) as $category) {
if (!in_array($category->cat_name, $exclude)) {
$new_the_category .= '<a href="'.get_bloginfo(url).'/'.get_option('category_base').'/'.$category->slug.'">'.$category->name.'</a>'.$separator;
}
}
echo substr($new_the_category, 0, strrpos($new_the_category, $separator));
?>  
0

Ok, try this:

<?php
$category = get_term_by( 'name', 'lastest news', 'category' );
$args = array (
    'tax_query' => array (
        array (
            'taxonomy' => 'category',
            'field'    => 'slug',
            'terms'    => $category->slug,
            'operator' => 'NOT IN'
        )
    )
);
query_posts($args);

This example need WP 3.1 to work. See more: Taxonomy parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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