Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Exclude posts from specific categories on blog second page WordPress

  • REFUNDED

This should be relatively simple, but adding the following seems to break the output (I get a server error when I do):

query_posts($query_string . '&cat=-331,-332,-333');

I just need to exclude categories 331, 332 and 333 from the output following this line (about 2/3 of the way through):
// Output content for page 2 onwards (non-frontpage)

Here's the summarised code:

<?php if ( $paged < 2 ) { // Do stuff specific to first page ?>

<?php if (have_posts()) : ?>

<?php $my_query = new WP_Query(array('showposts' => 1, 'category__not_in' => array(331,332,333)));
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>

<!-- Output first post -->
<?php
$id =$post->ID;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$pattern = '!<img.*?src="(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0];
?>


FIRST POST HERE


<?php endwhile; ?>

<div id="smaller-news" class="group">
<?php
$counter = 0; $counter2 = 0;
$new_wp_query = new WP_Query(array('showposts' => 6, 'category__not_in' => array(331,332,333)));
if ($new_wp_query->have_posts()) : while ($new_wp_query->have_posts()) : $new_wp_query->the_post();
// $counter++; $counter2++;
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts);
update_post_caches($posts);
$counter++; $counter2++;

?>

<!-- Output other posts -->
<?php if ($counter2 == 3) {
wcs_display_ad_block_page_1_item_3();
$counter2++;
} ?>

<?php get_template_part( 'content', 'post-listing' ); ?>

<?php if ($counter2 % 2){} else { breakfix(); } ?>

<?php endwhile; endif; ?>

<?php if ($counter == 1) {break;} ?>

<?php endif; ?>
</div>

<?php } else {
// Output content for page 2 onwards (non-frontpage)
?>

<?php
$counter_alt = 0;
while (have_posts()) : the_post();
$counter_alt++;
?>


<?php get_template_part( 'content', 'post-listing' ); ?>

<?php //Display adverts at appropriate intervals
if (($counter_alt == 3) || ($counter_alt == 3)) {
wcs_display_ad_block();
$counter_alt++;
}
if ($counter_alt == 8) {break;}
?>
<?php //Add hr class after each 2 posts to ensure even spacing
if ($counter_alt % 2){} else { breakfix(); } ?>

<?php endwhile; endif; ?>

<?php } ?>

Answers (0)

No answers yet.