0

I just tried slapping together a poor-man's "featured post" section with this exact code out of my index.php:

<div id="post-wrapper">
<?php if (is_home() && !is_paged()) : ?>

    <?php query_posts('cat=13&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>

        <div class="sticky" id="post-<?php the_ID(); ?>">

            <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

            <?php include('meta.php'); ?>

            <div class="entry">

                <?php the_excerpt(); ?>

                <div class="after-excerpt">
                    <?php if (has_tag()) { ?>
                        <div class="tags">
                            <img src="<?php bloginfo('template_url'); ?>/images/tag.jpg" alt="Tagged as:" />
                            <?php the_tags('', ', ', '<br />'); ?>
                        </div>
                    <?php } ?>

                    <div class="read-more-link">
                        <a href="<?php the_permalink(); ?>">Read More &raquo;</a>
                    </div>
                    <br style="clear: both" />
                </div>

            </div>

        </div>
    <?php endwhile; ?>

<?php endif; wp_reset_query(); ?>

<?php query_posts('cat=-13'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!-- do my thing for normal posts -->

So as you can see, I've tried using multiple loops (first time trying that too :P) and the result is great...on the front page of the blog! If I were to go to the 2nd page however, it displays only the non-Feature posts that were on the first page. So in essence, it's almost working but I need your help resolving this issue!

Also, if anyone reads this and has a better way of doing it I am all ears! This was simply my first attempt at making this feature without the use of a plugin :)

Thanks in advance, and any/all help is much appreciated!

EDIT :

Issue resolved. Wasn't correctly querying all other posts in 2nd loop.

Replaced:

<?php query_posts('cat=-13'); ?>

with:

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

and that simple fix did it for me :) hope someone else stumbles onto this and is helped as well!

0

1 Answer 1

1

First, if you want to load posts outside of the default query for the page, use WP_Query. Calling query_posts should be done only to modify parameters of the default query.

The pagination issue stems from calling query_posts, you're overwriting the page parameter (and all other parameters) by calling it in your template. If you want to retain the original parameters and modify them:

global $query_string; // get the global query_string for this query
query_posts( $query_string . '&cat=-13' ); // add to the query string whatever we want to change from the defaults

EDIT- oops, too slow. I would still change your featured query to use WP_Query instead. Once you're in the template, your default query for the page has already run. When you call query_posts you're throwing out that query and making a new one, which is inefficient and should be avoided if possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.