• Resolved martinfamily2005

    (@martinfamily2005)


    I want to only display the latest post on my home page, index.php , but I can not get it to work properly. I also tried one of the plugins, but that did not work either, it kept messing my page up. Is there a simple way to do this? I just need this functionality on my home page only, index.php. Here is my code:

    <?php include("header.php"); ?>
    
    <!-- BEGIN content -->
    <div id="content">
    
    	<?php
    	if (have_posts()) :
    	while (have_posts()) : the_post();
    	?>
    
    	<!-- BEGIN post -->
    	<div class="post">
    		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<a href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); ?></a>
    		<?php the_excerpt(); ?>
    		<p class="date"><?php the_time('F j, Y') ?></p>
    	</div>
    	<!-- END post -->
    
    	<?php endwhile; ?>
    	<p class="postnav">
    		<?php next_posts_link('&laquo; Older Entries'); ?> &nbsp;
    		<?php previous_posts_link('Newer Entries &raquo;'); ?>
    	</p>
    	<?php else : ?>
    	<div class="notfound">
    		<h2>Not Found</h2>
    		<p>Sorry, but you are looking for something that is not here.</p>
    	</div>
    	<?php endif; ?>
    
    </div>
    <!-- END content -->
    
    <?php get_sidebar(); get_footer(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter martinfamily2005

    (@martinfamily2005)

    I tried that before, and I just re-tried it, but it is not working. I just get the query_posts line as text on my index.php.

    Here is the code I used, please advise.

    <?php include("header.php"); ?>
    
    <!-- BEGIN content -->
    <div id="content">
    
    //The Query
    query_posts('posts_per_page=1');
    
    	<?php
    	if (have_posts()) :
    	while (have_posts()) : the_post();
    	?>
    
    	<!-- BEGIN post -->
    	<div class="post">
    		<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    		<a href="<?php the_permalink(); ?>"><?php dp_attachment_image($post->ID, 'thumbnail', 'alt="' . $post->post_title . '"'); ?></a>
    		<?php the_excerpt(); ?>
    		<p class="date"><?php the_time('F j, Y') ?></p>
    	</div>
    	<!-- END post -->
    
    	<?php endwhile; ?>
    	<p class="postnav">
    		<?php next_posts_link('&laquo; Older Entries'); ?> &nbsp;
    		<?php previous_posts_link('Newer Entries &raquo;'); ?>
    	</p>
    	<?php else : ?>
    	<div class="notfound">
    		<h2>Not Found</h2>
    		<p>Sorry, but you are looking for something that is not here.</p>
    	</div>
    	<?php endif; ?>
    
    </div>
    <!-- END content -->
    
    <?php get_sidebar(); get_footer(); ?>

    I know you said you tried a plugin, but did you try Different Posts Per Page?

    Thread Starter martinfamily2005

    (@martinfamily2005)

    i did not use that plugin originally. I just installed it, and it works great. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to display the LATEST POST ONLY on index.php’ is closed to new replies.