WordPress.org

Ready to get started?Download WordPress

Forums

Excluding a Category using wp_query - with working page navigation (5 posts)

  1. WebbKat
    Member
    Posted 1 year ago #

    I was having problems with the page navigation(empty pages or staying on the first page w/excluded categories) so i decided to use this wp_query code for my blog loop which is NOT on the homepage:

    <?php twentyeleven_content_nav( 'nav-above' );
         <?php /* Start the Loop */ ?>
    
    <?php //query_posts('paged='.$paged);
    	$temp = $wp_query;
    	$wp_query= null;
       	$wp_query = new WP_Query();
            $wp_query->query('showposts=5'.'paged='.$paged); ?>
    
    <?php $recentPosts = new WP_Query();
          $recentPosts->query('showposts=5'.'&paged='.$paged) ?>
    <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    
    <?php get_template_part( 'content', get_post_format() ); ?>
    	<?php endwhile; ?>
            <?php $wp_query = null; $wp_query = $temp;?>
    
    <?php twentyeleven_content_nav( 'nav-below' ); ?>

    Page Navigation is working,
    but now I'm having problems excluding a category.
    Any code I found with an excluded category messed up the pave nav.
    I want to exclude two categories and have a working page navigation, but I continue to go in circles.

  2. Peter_L
    Member
    Posted 1 year ago #

    Try using wp_list_pages to build your nav
    http://codex.wordpress.org/Function_Reference/wp_list_pages

  3. Peter_L
    Member
    Posted 1 year ago #

  4. WebbKat
    Member
    Posted 1 year ago #

    this is referring to actual pages, i might of stated something wrong confusing actual pages and post loop pages.

    I'm referring to post nav/loop nav.(ex. older post, newer post)

    i just need code to exclude categories within the blog loop, but i havn't found a code that worked with wp_query that didn't break the "post nav" (ex. older post, newer post).

  5. Peter_L
    Member
    Posted 1 year ago #

    I'm not really familiar with twentyeleven so the code you show is a bit confusing to me.

    In theory it should be something like '&cat=-12,-34,-56'

Topic Closed

This topic has been closed to new replies.

About this Topic