Trying to display current post on single.php and the previous 3
-
When the user clicks on a post (on the homepage) it takes them to the single.php template where I’d like it to display that post in detail and the previous 3 below. This sounds easy but has been quite a hassle. I need to know how to display the previous posts in reference to the current post.
Here is the code for the single.php page:
<?php
/**
* @package WordPress
* @subpackage WPG_Theme
*/
get_header();
?><div id="contentArea">
<table cellspacing="0">
<tr>
<td>
<div id="leftColumn"><?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="blogPosts">
<h1>Latest from WPG</h1>
<div id="latestBlog">
<!--<img src="wp-content/themes/wpg/images/blog-photo.jpg" width="163" height="140" alt="" />-->
<h2>" rel="bookmark"><?php the_title(); ?></h2>
<h3>Published <?php the_time('F jS, Y') ?></h3>
<p><?php the_content(); ?></p>
<p><?php wp_list_comments(); ?></p>
</div>
</div><?php comments_template(); ?>
<?php endwhile; else: ?><p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
<!-- Next 3 Blog Posts -->
<div class="blogPosts">
<h1>Older Posts</h1>
<table cellspacing="0" class="postGrid">
<tr class="noDots">
<th class="column1">TITLE</th>
<th class="column2">Comments</th>
<th class="column3">Last updated</th>
</tr><!--query_posts('posts_per_page=3','orderby=asc');-->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<tr>
<td class="column1">
<img src="wp-content/themes/wpg/images/grid-photo.jpg" width="68" height="62" alt="" />
<h4>" rel="bookmark"><?php the_title(); ?></h4>
<p>Published: <?php the_time('m/d/Y') ?></p>
<p>Summary: <?php echo get_the_excerpt(); ?></p>
</td>
<td class="column2">"><?php comments_number('0','1','%'); ?></td>
<td class="column3"><?php the_modified_date(); ?></td>
</tr><?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?></table>
<div class="rightArrowLink">View All Posts</div>
</div></div> <!-- End Left Column -->
</td>
<td><?php get_sidebar(); ?>
<?php get_footer(); ?>I have been searching for a solution everywhere. No luck yet.
I have researched query_posts and <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> loop methods and have not found the option to list previous by id or current post.
Maybe there is a plugin or snippit I’ve overlooked but hopefully someone has had this problem before. Thanks for any help!
- The topic ‘Trying to display current post on single.php and the previous 3’ is closed to new replies.