• Ken
      Permalink to comment#


      Do you know how to code this if you used /work/ instead of an id.


  1. backpackers
    Permalink to comment#

    i use it within looping. is it ok?

    • backpackers
      Permalink to comment#


       <?php if (have_posts()) : ?>
       <?php query_posts($query_string.'&cat=-70'); while (have_posts()) : the_post(); ?>
      - - -  content - - -
      <?php endwhile; ?>
      <?php wp_pagenavi(); ?>
      <?php else : ?>
      <?php include(TEMPLATEPATH . '/404.php'); ?>
      <?php endif; ?>

      because i’m using wp_pagenavi… is it ok?

  2. Dexter

    Messed with pagination, you guys should check some things before starting giving tips.

  3. W@RL0CK
    Permalink to comment#
                <?php twentyeleven_content_nav( 'nav-above' ); ?>
                <?php /* Start the Loop */ ?>
                <?php while ( have_posts()) : the_post(); ?>
                    <?php get_template_part( 'content', get_post_format() ); ?>
                <?php endwhile; ?>
                <?php twentyeleven_content_nav( 'nav-below' ); ?>
            <?php else : ?>
                <article id="post-0" class="post no-results not-found">
                    <header class="entry-header">
                        <h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
                    </header><!-- .entry-header -->
                    <div class="entry-content">
                        <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
                        <?php get_search_form(); ?>
                    </div><!-- .entry-content -->
                </article><!-- #post-0 -->
            <?php endif; ?>

    Something goes wrong with the pagination. As in it hides the category specified but certain non-specified categories don’t show up. Seems, that the solution provided by you guys messes up the pagination code. Please Help !!!

  4. Aaron
    Permalink to comment#

    Uhh, not sure what happened, but I meant to post that even though this post is a little old, people who come across it today might want to take care in using $query_posts() since it can be a very risky function. I’d suggest using WP_Query() instead.

    Here’s a sample from a project I’m working on now (which…uhm, you got a little sample of above…)

            <ol class="posts-list">
                <?php // exclude posts in gallery category
                    $catid = get_cat_ID('gallery');
                    $args = array('cat' => '-' . $catid);
                    $the_query = new WP_Query( $args );
                    if ( $the_query->have_posts() ) : ?>
                        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
                                <h1 class="entry-title">
                                    <a href="<?php the_permalink(); ?>" title="<?php echo get_the_title(); ?>" rel="bookmark"><?php the_title(); ?></a>
                                <span class="entry-date"><?php echo get_the_date(); ?></span>
                                <span class="post-tags"><?php echo the_tags("",",",""); ?></span>
                    <?php endwhile; ?>
                <?php endif; ?>
    • Rhys
      Permalink to comment#

      Brilliant, this is exactly what I was looking for. Thank you Aaron.

  5. Vitor
    Permalink to comment#


    global $query_string;
    query_posts($query_string . '&cat=-45, -46');
    while ( have_posts() ) : the_post()
    • jayshankar krish
      Permalink to comment#

      Thank You victor, your code has come handy for one of my website. Thanks a lot!!

  6. Markus
    Permalink to comment#

    Excluding specific categories in certain pages seems to be more tricky.
    This code below for exmaple does not work. Any idea what to do if I want to show certain categories on certain pages (= excluding the rest)?

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

We have a pretty good* newsletter.