Exclude Category fomr Blog Page (WP How-to)

Simply for you guys… Pain in the **** for me!

All I need to do is exclude category&tag_ID=3&post_type=post from:

<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<?php if (have_posts()) : ?>

<div id="content">
    <!--page.php-->
<div id="post" class="post clearfix">

            <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

	<!--post title-->
    <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>

	<!--post text with the read more link-->
<?php the_excerpt(); ?>

	<!--for paginate posts-->
	<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>

    <?php //comments_template(); // uncomment this if you want to include comments template ?>


	<?php endwhile; // end of one post ?>
<div class="page-nav">
<?php 	 wp_pagenavi(); ?>    </div>
	<?php else : // do not delete ?>
	<h3>Page Not Found</h3>
    <p>We're sorry, but the page you are looking for isn't here.</p>
    <p>Try searching for the page you are looking for or using the navigation in the header or sidebar</p>

    <?php
endif; // do not delete ?>

<!--page.php end-->
</div>
</div>
<?php endif; ?>
<?php get_sidebar(' '); ?>
<?php get_footer(' '); ?>

I know it’s somewhere in the "php query there at the top… But I can’t figure out how to incorporate it so that it doesn’t show… Any help would be greatly appreciated.

THANKS!

–Scott G.

Can you provide a better explanation of what it is doing now, that you don’t want it to do? I’m not sure I follow what you are trying to achieve.

stlheroinhelp.org/blog/

^^^ see the post “test” it’s categorized under “Memorial” and I don’t want those posts to show up on the blog page with other posts. I want to exclude all posts tagged with “Memorial” from the blog page. I have another section where all those appear “/category/memorial/”

On this page, someone recommends the following plugin, [url=http://www.fidgeting.net/wordpress-plugins/ultimate-category-excluder/]Ultimate Category Excluder

Then on this page, it seems you just need to add before your if (have_posts()) statement

query_posts( 'cat=-X' ); // replace X with the category ID, leave the minus sign

I’ve been trying different variations of:

<?php query_posts( 'cat=-3' ); ?>
            <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<?php query_posts('cat=-3'); ?>
<?php if (have_posts()) : ?>

<div id="content">
    <!--page.php-->
<div id="post" class="post clearfix">

            <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

I don’t really want to have to use another plugin for this and don’t want to have to edit much except for the blog.php template which is used to display blog posts… I just want to EXCLUDE “Memorials” which is Category ID 3… Can’t seem to figure this one out…

Try just updated the following line

<?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>

To

<?php query_posts(array('category__not_in' => -3,'paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>

…Wow… Ok solved it…

NOT THIS:

<?php query_posts( 'cat=-3' ); ?>
            <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?> 

BUT THIS:

            <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
<?php query_posts( 'cat=-3' ); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

ah, okay. Do you still only get 10 posts per page? And does the paging actually still work? Or do you have to do a combine effort like so (although I am unsure if it works)

<?php query_posts(array('category__not_in' => -3,'paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>

Found this too http://wordpress.org/support/topic/query_posts-exclude-not-working-with-paging

It says, using the cat=-3 may break your paging and they all suggest doing the following:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10;
query_posts('cat=-3&paged='.$paged.'&posts_per_page='.$posts_per_page);

@cpradio

You’re right, the script did break the paging…

How do I implement your above code? I tried turning this:

            <?php query_posts(array('paged' => get_query_var('paged'),'posts_per_page' =>10)); ?>
            <?php query_posts('cat=-3'); ?>
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

Into this (as recommended above ^^^):

            <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
            <?php $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10; ?>
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

Left me with a blank page though…

Because you forgot the all important query_posts line

            <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10;
            query_posts('cat=-3&paged='.$paged.'&posts_per_page='.$posts_per_page); ?>
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post();?>

Thank you for the quick response cpradio. I changed the code and it’s not doing anything for me unfortunately. There are 12 posts on the page: http://stlheroinhelp.org/blog/

I concede Lol

Okay, here is another attempt

Remove this

            <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $posts_per_page = (get_query_var('posts_per_page')) ? get_query_var('posts_per_page') : 10;
            query_posts('cat=-3&paged='.$paged.'&posts_per_page='.$posts_per_page); ?>

Replace it with

            <?php query_posts($query_string . '&cat=-3'); ?>

I’ve got only 10 posts being displayed but I for the life of me cannot figure out how to add page navigation/pagination whatever it’s called… The navigation that populates at the bottom of the page to go to the next page with 10 posts…

<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<?php if (have_posts()) : ?>

<div id="content">
    <!--page.php-->
<div id="post" class="post clearfix">
<div id="blog-heading"><h1>Blog &amp; News Articles</h1></div>

<?php
    $recentPosts = new WP_Query();
    $recentPosts->query('posts_per_page=10&cat=-3');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
	<!--post title-->
    <div id="h2-memorial"><h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2></div>

	<!--post text with the read more link-->
<?php the_excerpt(); ?>

	<!--for paginate posts-->
	<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>

    <?php //comments_template(); // uncomment this if you want to include comments template ?>


	<?php endwhile; // end of one post ?>
<div class="page-nav">
<?php 	 wp_pagenavi(); ?>    </div>
	<?php else : // do not delete ?>
	<h3>Page Not Found</h3>
    <p>We're sorry, but the page you are looking for isn't here.</p>
    <p>Try searching for the page you are looking for or using the navigation in the header or sidebar</p>

    <?php
endif; // do not delete ?>


<!--page.php end-->
</div>
</div>
<?php get_sidebar(' '); ?>
<?php get_footer(' '); ?>

CPRADIO if you help me solve this I want your Paypal email address…

I believe the solution will be similar to http://www.sitepoint.com/forums/showthread.php?909046-WP-How-to-10-posts-per-page-with-page-navigation-on-custome-template-I-m-stuck, so once we get that solved, it should be copy and paste :wink:

Okay, I have it solved

Replace

    $recentPosts = new WP_Query(); 
    $recentPosts->query('posts_per_page=10&cat=-3');

With

    $recentPosts = new WP_Query( array( 'cat' => -3, 'posts_per_page' => 10, 'paged' => get_query_var('paged') ) ); 

Then replace

<?php      wp_pagenavi(); ?>

With

<?php      wp_pagenavi( array( 'query' => $recentPosts ) ); ?>

CPRADIO!

You are the friggin MAN! I really can’t thank you enough! Thank you thank you thank you! You solved what’s been eating at me for 2-entire days… And you were just helping. Thank you so much!

-Scott G.