You probably need to add a call to query_posts() to the code you copied into sidebar.php. I suspect that it needs to add the ‘posts_per_page’ argument set to the number of entries you want to show. The code should be similar to this:
<?php
global $wp_query;
query_posts(
array_merge(
$wp_query->query,
array('posts_per_page' => 5)
)
);
?>
That code would go just before the if (have_posts()) call that usually starts the loop.
Currently my ‘sidebar.php’ contains:
<?php
$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';
/* Run the loop for the category page to output the posts.
* If you want to overload this in a child theme then include a file
* called loop-category.php and that will be used instead.
*/
get_template_part( 'loop', 'category' );
?>
and the loop takes place in ‘loop-category.php’
I think what is happening is, because I’m calling the same loop as the category page but inside of a post it can only see that post and does not output the rest. However I have no idea how to instruct the loop to call the entire category from inside a post.
Although I may be entirely wrong, I’m currently clueless.
You are on the right track. Copy loop-category.php to loop-my-category.php and add the query_posts() call there. Then change the sidebar.php to get_template_part('loop, 'my-category' );
Unfortunately it’s still only showing the current post. I can’t think what could be going wrong.
It is almost impossible to guess what is wrong. Please put the code for loop-my-category.php in a pastebin and post a link to it here.
Since I can’t test the code, this is just a guess, but try changing the query to this:
<?php
$cat = get_query_var('cat');
query_posts(
array(
'posts_per_page' => 5,
'cat' => $cat,
)
);
?>
Ahh-ha!
It appears to have worked good sir.
Except now it appears to be showing both full posts on the page too… I can’t help but be completely confused again =P
http://krizzyb.com/video/?p=1
Then you will need to save the old query and restore it at the end. Change the query to this:
<?php
global $wp_query;
$save_query = $wp_query;
$cat = get_query_var('cat');
query_posts(
array(
'posts_per_page' => 5,
'cat' => $cat,
)
);
?>
and add this as the last line:
<?php $wp_query = $save_query; ?>
Done that, but still seems to be messing up. Could it be a problem elsewhere?
Also the comments section disappears, if that’s a clue to where the problem may lie.
The only other thing I can suggest is that you change the sidebar query to use WP_Query, but that involves changes in several places.
Change the query to this:
<?php
$cat = get_query_var('cat');
$my_query = new WP_Query(
array(
'posts_per_page' => 5,
'cat' => $cat,
)
);
?>
Then,
- change all have_posts() to $my_query->have_posts()
- change all the_post() to $my_query->the_post()
YOU SIR ARE A GOD!
That appears to have solved it =P
Thank you very much for your time and knowledge =)