• Resolved dmx09

    (@dmx09)


    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)
  • try and switch the order of these two lines:

    </div>
    <?php endwhile; ?>

    to this:

    <?php endwhile; ?>
    </div>

    you were closing the div for each post in the loop = disaster ??

    Thread Starter dmx09

    (@dmx09)

    Oh I see, will give that a go, many thanks!

    Thread Starter dmx09

    (@dmx09)

    Doesn’t look like that did the trick..
    This is the entire sidebar.php if anyone has any thoughts…

    [code moderated as per forum rules - please use the pastebin]

    can you post a link to your site to illustrate the problem?

    Thread Starter dmx09

    (@dmx09)

    Unfortunately, I can’t post the url of this particular site here but I’ve done a quick screen grab if that helps.. Basically, the sidebar is pushing down the main content div for some reason. It’s fine if I only display 1 post in the sidebar but any more than that it breaks..

    It looks as tough the 2nd post is not being wrapped in a ‘widget’ class and my best guess is that is the issue..

    Image here

    images alone are no use as one cannot see the html/css interaction.

    only sometimes, images might be good in connection with a link to the site to point to specific issues.

    if you can’t post a link for whatever reason (which i totally respect), you are unfortunately on your own solving the problem.

    check float issues, overflow issues, widths, etc.

    Thread Starter dmx09

    (@dmx09)

    many thanks for your help, I’m sure I’ll sort it eventually! ??

    Thread Starter dmx09

    (@dmx09)

    Just to let you know, I re-uploaded the sidebar file this morning having only moved the ‘endwhile’ code as per your first suggestion and it works!

    Not sure what happened over the weekend, maybe I had too many beers the night before!

    Anyway, thanks again! It’s very much appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Displaying posts in sidebar using sidebar.php’ is closed to new replies.