• hardworking

    (@hardworking)


    Hi all

    My single.php is showing more than one post. Here is the code below, any advice much appreciated.

    <?php get_header(); ?>
    
          <td width="5" bgcolor="#FFFFFF"></td>
          <td valign="top" class="masterContentBlock">
            <!--BEGIN  CONTENT-->
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
    			<div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
    		</div>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><?php the_title(); ?></h2>
    
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    				<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
    
    				<p class="postmetadata alt">
    					<small>
    						This entry was posted
    						<?php /* This is commented, because it requires a little adjusting sometimes.
    							You'll need to download this plugin, and follow the instructions:
    							http://binarybonsai.com/wordpress/time-since/ */
    							/* $entry_datetime = abs(strtotime($post->post_date) - (60*120)); echo time_since($entry_datetime); echo ' ago'; */ ?>
    						on <?php the_time('l, F jS, Y') ?> at <?php the_time() ?>
    						and is filed under <?php the_category(', ') ?>.
    						You can follow any responses to this entry through the <?php post_comments_feed_link('RSS 2.0'); ?> feed.
    
    						<?php if ( comments_open() && pings_open() ) {
    							// Both Comments and Pings are open ?>
    							You can <a href="#respond">leave a response</a>, or <a href="<?php trackback_url(); ?>" rel="trackback">trackback</a> from your own site.
    
    						<?php } elseif ( !comments_open() && pings_open() ) {
    							// Only Pings are Open ?>
    							Responses are currently closed, but you can <a href="<?php trackback_url(); ?> " rel="trackback">trackback</a> from your own site.
    
    						<?php } elseif ( comments_open() && !pings_open() ) {
    							// Comments are open, Pings are not ?>
    							You can skip to the end and leave a response. Pinging is currently not allowed.
    
    						<?php } elseif ( !comments_open() && !pings_open() ) {
    							// Neither Comments, nor Pings are open ?>
    							Both comments and pings are currently closed.
    
    						<?php } edit_post_link('Edit this entry','','.'); ?>
    
    					</small>
    				</p>
    
    			</div>
    		</div>
    
    	<?php comments_template(); ?>
    
    	<?php endwhile; else: ?>
    
    		<p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>
    
        <!--END  CONTENT-->
          </td>
        </tr>
    
      </table>
    
     <!--END GLOBAL CONTENT BLOCK-->
    
    </div></div>
    
    <?php get_footer(); ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Change this:
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    to

    <?php if (have_posts()) : the_post(); ?>

    and

    <?php endwhile; else: ?>

    to

    <?php else: ?>

    Thread Starter hardworking

    (@hardworking)

    awesome – thanks Zeo 🙂

    Thread Starter hardworking

    (@hardworking)

    zeo – have swapped the code as you suggested. single.php will now only show my latest post, no matter what post I try and view… any advice?

    Code below….

    <?php get_header(); ?>
    
          <td width="5" bgcolor="#FFFFFF"></td>
          <td valign="top" class="masterContentBlock"> 
    
          <h1>Latest News</h1>
            <!--BEGIN  CONTENT-->
    <?php if (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<h2><?php the_title(); ?></h2>
                <br />
    <?php the_time('jS F Y') ?>
    <br />
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    				<?php the_tags( '<p>Tags: ', ', ', '</p>'); ?>
    
    			</div>
    		</div>
    
    	<?php comments_template(); ?>
    
    <?php else: ?>
    		<p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>
    
        <!--END  CONTENT-->
          </td>
        </tr>
    
      </table>
    
     <!--END GLOBAL CONTENT BLOCK-->
    
    </div></div>
    
    <?php get_footer(); ?>

    Probably plugins? query_posts? WP_Query? Check if any exist.

    Thread Starter hardworking

    (@hardworking)

    I think the issue is in my sidebar.php – as when i remove this, it works ok. this is the code in my sidebar.php – can you recommend? many thanks for your help…

    <div class="sideHighlightBlock" style="height:15px;padding-top:12px;"><h4>Latest News</h4></div>
    
    <div class="sideHighlightBlock">
    	<?php query_posts("showposts=4&category_name=Featured"); $i = 1; ?>
        <?php while (have_posts()) : the_post(); ?>
    	<!-- <div class="clearfloat"> -->
    	<?php $values = get_post_custom_values("Image");
    	if (isset($values[0])) { ?>
          <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    	<img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
    $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=65&h=65&zc=1&q=65"
    alt="<?php the_title(); ?>" class="left" width="65px" height="65px"  /></a>
          <?php } ?>
    	  <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    	  <p><?php the_excerpt(); ?></p>
    
          <?php endwhile; ?></div>

    see: http://codex.wordpress.org/Function_Reference/wp_reset_query

    I think to be safe, it’s best to use WP_Query for that thing u doing in the sidebar. Search around, there’s many tutorial.

    Thread Starter hardworking

    (@hardworking)

    cheers zeo – wp_reset_query has fixed it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘single.php – showing more than one post’ is closed to new replies.