… 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="https://wordpress.stackexchange.com/questions/116412/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('category-thumb-2'); ?></a>
<div class="blackframe">
<h2><a href="https://wordpress.stackexchange.com/questions/116412/<?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.