Displaying posts in sidebar using sidebar.php
-
Hi all,
I’ve got a site where I want to display posts in the sidebar from a specific category. I found some code which I’ve wrapped inside the ‘widget’ class so it will ingerit the correct styling.For some reason, if I show more than one post it breaks (by pushing the main content down the page).
It looks like the code I’ve added only places the ‘widget’ class around the first post and not the 2nd. Any thoughts much appreciated!
Here’s the code…
<!-- Posts in Sidebar --> <div class="widget"> <?php $recent = new WP_Query(); ?> <?php $recent->query('cat=22&showposts=3'); ?> <?php while($recent->have_posts()) : $recent->the_post(); ?> <?php if ($wpzoom_sidebar_thumb_show == 'Yes') { // Here stars the part that shows a thumb and related post to individual articles/pages if ( is_single() || is_page()) : unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) { $thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' ); $img = $thumbURL[0]; } else { unset($img); if ($wpzoom_cf_use == 'Yes') { $img = get_post_meta($post->ID, $wpzoom_cf_photo, true); } else { if (!$img) { $img = catch_that_image($post->ID); } } } if ($img) { $img = wpzoom_wpmu($img); ?> <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $img ?>&w=231&h=122&zc=1" alt="<?php the_title(); ?>" /><br/><br/><?php } ?> <?php endif ; } ?> <a href="<?php the_permalink(); ?>"> <div style="font-weight: bold"><?php the_title(); ?></a></div> <?php the_excerpt(); ?> </div> <?php endwhile; ?> <!-- end Posts in Sidebar -->
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Displaying posts in sidebar using sidebar.php’ is closed to new replies.