• I have one specific category (let’s call it photography) that I do not want to display in my sidebar with the 10 most recent posts, but I do want to display a list of recent posts in the photography category below the main list… exactly how do I use query_posts to select only posts from the photography catagory, and how do I eliminate that catagory from my main list? I used the code below but it does not work. I am using WP 2.1… trying to avoid another plugin if possible, is it possible to just code this setup?

    <?php query_posts("cat=5"); ?>
    <?php if (have_posts()) : ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    
    <?php endwhile; ?>
    <?php endif; ?>
    </div>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter thebindlestick

    (@thebindlestick)

    anyone?

    This is the code that I used. I stole it from Rhymed Code

    <?php query_posts( 'category_name=asides&showposts=4' ); ?>
    <?php if( have_posts() ) : ?>

    <ul class="asides">
    <?php while( have_posts() ) : the_post(); ?>
    <li id="post-<?php the_ID(); ?>">
    <span class="aside">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permalink: <?php the_title(); ?>">
    <?php the_title(); ?>`
    </a>
    </span>
    <br/>
    <?php echo wptexturize(the_excerpt_reloaded(15,'','',false)); ?>
    <span class=”aside”>(<?php comments_popup_link (‘0′,’1′,’%’,’C’)?>)`
    </span>
    </li>
    <?php endwhile; ?>
    </ul>
    <?php endif; ?>

    Oh, and in the index.php file, I have

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-26&paged=$paged");
    }
    ?>

    (before the If (have_posts() )

    Thread Starter thebindlestick

    (@thebindlestick)

    The solution I ended up with after two days of banging my head into my monitor is that The Lop in my index and The Loop in my sidebar were interfering with eachother. I found this solution and it is the only thing I can get to work; see first and last lines of code specifically:

    <?php $temp_query = $wp_query; ?>
    <?php query_posts(‘cat=-5’); ?>

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

    <?php while (have_posts()) : the_post(); ?>

    — do stuff —

    <?php endwhile; ?>

    <?php endif; ?>
    <?php $wp_query = $temp_query; ?>

    Can anyone see why this is a bad idea in WP 2.1?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘query_posts in sidebar’ is closed to new replies.