WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have about 10 different category posts etc.

As you know, withing each category there is the next and previous navigation to toggle between posts. When you reach the Last post in a category, the next navigation then takes you to the NEXT category...

My question is, is there there a way to loop only withing the category with the next and previous?

    // The Category Loop

if (function_exists('childtheme_override_category_loop'))  {
    function thematic_category_loop() {
} else {
    function thematic_category_loop() {

        while (have_posts()) : the_post(); 

                thematic_abovepost(); ?>

                <div id="post-<?php the_ID();
                    echo '" ';
                    if (!(THEMATIC_COMPATIBLE_POST_CLASS)) {
                        echo '>';
                    } else {
                        echo 'class="';
                        echo '">';
                    thematic_postheader(); ?>
                    <div class="entry-content">
<?php thematic_content(); ?>

                    </div><!-- .entry-content -->
                    <?php thematic_postfooter(); ?>
                </div><!-- #post -->



} // end category_loop
share|improve this question

i had the same problem with one of my sites and i used this hack: on your themes category.php (or if your doesn't have one then archive.php ) before the loop part witch is something like this:

if ( have_posts() ) : while ( have_posts() ) : the_post();

add this code

if (is_category()){
     $category = $current_category = single_cat_title("", false); 
    if(isset(get_query_var( 'page' ))){
        $page = get_query_var( 'page' );
        $page = 1;
    global $wp_query;
            array( 'cat' => $category, 'paged' => $page ),

this should loop only within the category.

share|improve this answer
THANKS!!!!!!!!!!!!!!!! I will try this. – Driftwood Jan 19 '11 at 16:25
Ok, I tried it and this is the error I get "Fatal error: Can't use function return value in write context in" – Driftwood Jan 19 '11 at 16:51
paste your category.php code here – Bainternet Jan 19 '11 at 17:28
I added it to my original posting, since I could not add that many characters. – Driftwood Jan 19 '11 at 23:46
that's nothing to do with the query but the custom functions the theme uses or you not really sure like post_class() , thematic_belowpost(); ,thematic_post_class(); so i can't help you here just try to remove them and the code above while (have_posts()) : the_post(); and add the code i posted – Bainternet Jan 20 '11 at 0:02

This is what i use in my child themes functions file at this time which only links posts within each category.

add_action('your_hook', 'wpsites_nav_links', 25 );
function wpsites_nav_links() {
if( !is_single() ) 

previous_post_link('<span class="single-post-nav previous-post-link">%link</span>', '&lt;&lt; Previous Post in Category', TRUE);
next_post_link('<span class="single-post-nav next-post-link">%link</span>', 'Next Post in Category &gt;&gt;', TRUE);

Replace your_hook with your themes after content hook or use the_content filter.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.