• Resolved compositeone

    (@compositeone)


    Hi all, been lurking he for months/years… but this is my first post.

    On my home page, http://www.composite-projects.co.uk I have a section that displays the titles of the latest posts. I would like it to display the titles as it is but for the first post ONLY to also display the post.

    The code I’m using at the moment is:

    <div id="latestNews">
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    				<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    
    		<?php endwhile; ?>
                            </div>
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
                    </div>
    <?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    </div>

    How would I mod this to do what I need. I’m afraid to say my php is non-existent.
    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • <div id="latestNews">
    	<?php if (have_posts()) : ?>
    <?php   $count = 0; ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    				<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <?php
    $count++;
    if ($count <= 1) {
      the_content();
    }
    ?>
    		<?php endwhile; ?>
                            </div>
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
                    </div>
    <?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    </div>

    [edit correct code per below ]

    MichaelH,

    If not mistaken, your code is missing closing bracket right after the_content();

    Thread Starter compositeone

    (@compositeone)

    The code was missing the }, thanks both. Very much appreciated.

    For the sake of completeness, below is the fully correct code:

    <div id="latestNews">
    	<?php if (have_posts()) : ?>
    <?php   $count = 0; ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    				<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <?php
    $count++;
    if ($count <= 1) {
    the_content();}?>
    		<?php endwhile; ?>
                            </div>
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
                    </div>
    <?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    </div>

    Thanks for the correction–edit above completed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display the post for the first latest article only’ is closed to new replies.