Hi all
Is there a way to display an archive of the current category in the sidebar?
Example:
When you navigate to a post in a category there should appear a list of the posts in that but only that category.
How can I do that?
Thanks
Hi all
Is there a way to display an archive of the current category in the sidebar?
Example:
When you navigate to a post in a category there should appear a list of the posts in that but only that category.
How can I do that?
Thanks
In a sidebar, if single post, for the first category of that post, display 5 posts in that category, excluding the single post.
Related:
http://wordpress.org/search/category+single+sidebar?forums=1
http://wordpress.org/support/topic/257858?replies=4
http://wordpress.org/support/topic/179138?replies=4
http://wordpress.org/support/topic/252228
<?php
if ( is_single() ) {
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$first_cat = $cats[0];
$args=array(
'cat' => $first_cat, //cat__not_in wouldn't work
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'Related Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
} //if ($my_query)
} //if ($cats)
wp_reset_query(); // Restore global post data stomped by the_post().
} //if (is_single())
?>Hi,
Check with this plugin:
http://wordpress.org/extend/plugins/category-based-archives/
Thanks,
Shane G.
Brilliant code... though one small problem. I'm trying to style the "Related posts" heading to be <h3 class="widgettitle">
I add the <h3> around this code, like this:
<h3 class="widgettitle">
<?php
if ( is_single() ) {
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$first_cat = $cats[0];
$args=array(
'cat' => $first_cat, //cat__not_in wouldn't work
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'Related Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?></h3>
But, i end up with two </h3>
So, I'm wondering where I can put the tag to end up with just one?
I would really appreciate a hint where i could put the style tags, these are a few of the variations i've tried, and which all produce errors:
<span class="h3">'echo 'More on the same subject';'</span>
'<span class="h3">'echo 'More on the same subject';'</span>'
echo '<span class="h3">''More on the same subject';'</span>'
<span class="h3">if( $my_query->have_posts() ) {
echo 'More on the same subject';</span>
'<span class="h3">'if( $my_query->have_posts() ) {
echo 'More on the same subject''</span>';
Where, and how, is the correct way to insert a style tag here? :-)
I finally figured it out! If anyone is reading, this is the solution:
echo '<h3>More on the same subject</h3>';
This topic has been closed to new replies.