Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question already has an answer here:

Under "Settings" => "Reading", I have set "Blog pages show at most" to 6.

I have created a category called 1970s where one can see all the best Rock albums of the decade -> Meanwhile, I have created subcategories (1970, 71, 72, 73 etc...) where one can see the best albums of the respective year.

Here is the problem(s), in the subcategories I am getting exactly the same results as in the parent category + pagination is not working.

I am using the Genesis Framework and I am working with the Sample theme, Here is my custom category.php file:

function rock_custom_loop() { ?>

    <header class="category_title_wrap">

        <h1 class="gold_title">The Verybest of the:  <?php echo single_cat_title( '', false ) ?></h1>

        <?php if ( category_description() ) :  ?>
            <div class="category_description"><?php echo category_description(); ?></div>
        <?php endif; ?>

    </header><!-- category_title_wrap -->

    <?php
    global $post;

    $args = array(
        'post_type'      => 'post',
        'post_status'    => 'publish',
        'paged'          => get_query_var( 'paged' )
    );

    global $wp_query;
    $wp_query = new WP_Query( $args );

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

            <div class="w_one_fourth">

                <div class="postimage">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumb-2'); ?></a>

                <div class="blackframe">
                    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                </div><!-- blackframe -->

                </div><!-- postimage -->

            </div><!-- griditemleft -->

        <?php
        endwhile;
        do_action( 'genesis_after_endwhile' );
    endif;

    wp_reset_query();
}

add_action( 'genesis_loop', 'rock_custom_loop' );
remove_action( 'genesis_loop', 'genesis_do_loop' );


genesis();

So I hope you can help find the bug (Subcategories + pagination)!

I have attached the following 2 pictures for visualization

Parent Category

enter image description here

share|improve this question

marked as duplicate by Chip Bennett, Johannes Pille, toscho Oct 31 '13 at 14:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Since Genesis is a commercial theme, you're more likely to get help on their support forum. –  Wyck Oct 2 '13 at 5:14

1 Answer 1

... in the subcategories I am getting exactly the same results as in the parent category ...

That is what you told PHP to do.

By the time the category.php file is processed, the $wp_query object contains a list of all posts that from the current category.

This code throws that object away and replaces it with an object of all posts.

$args = array(
    'post_type'      => 'post',
    'post_status'    => 'publish',
    'paged'          => get_query_var( 'paged' )
);

global $wp_query;
$wp_query = new WP_Query( $args );

Try this:

<?php

// Add category header.
add_action( 'genesis_before_loop', 'rock_category_header' );

// Replace Genesis loop with custom loop.
remove_action( 'genesis_loop', 'genesis_do_loop'  );
   add_action( 'genesis_loop', 'rock_custom_loop' );

genesis();


/**
 * Add category header.
 */
function rock_category_header() {
?>
    <header class="category_title_wrap">

        <h1 class="gold_title">The Very best of the: <?php single_cat_title() ?></h1>

    <?php if ( category_description() ) :  ?>
        <div class="category_description">
            <?php echo category_description(); ?>
        </div>
    <?php endif; ?>

    </header><!-- category_title_wrap -->

<?php
}

/**
 * Replace Genesis loop with custom loop.
 */
function rock_custom_loop() {

    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post();
?>
    <div class="w_one_fourth">

        <div class="postimage">
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumb-2'); ?></a>

            <div class="blackframe">
                <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            </div><!-- blackframe -->

        </div><!-- postimage -->

    </div><!-- griditemleft -->

<?php
        }
        do_action( 'genesis_after_endwhile' );

    } else {
        do_action( 'genesis_loop_else' );
    }

    wp_reset_query();
}

I left the <!-- griditemleft --> comment in, but there is no griditemleft class or id attribute.

share|improve this answer

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