Hello,
I would like to add a dynamic list of posts by category to my sidebar. For example, if I am viewing a single post from category "2", the sidebar would display links to all posts in category "2".
How would I do this?
thanks!
Hello,
I would like to add a dynamic list of posts by category to my sidebar. For example, if I am viewing a single post from category "2", the sidebar would display links to all posts in category "2".
How would I do this?
thanks!
I thought I'd seen this question before...
This search:
http://wordpress.org/search/category+single+sidebar?forums=1
found, among othere, these three possibilities:
http://wordpress.org/support/topic/257858
http://wordpress.org/support/topic/179138
http://wordpress.org/support/topic/252228
Thank you! Truly, effective searching is an art! :)
This code worked for me:
<?php
if ( is_single() ) {
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$first_cat = $cats[0];
$args=array(
'cat' => $first_cat,
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'More';
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())
?>Thanks for the code snippet eveums!
How can I make it into a drop down menu?
This topic has been closed to new replies.