Reputation: 55323
I know that traditionally you can have 2 main pages: the static page (front-page.php
)and the page for the last posts(home.php
).
Right now, front-page.php (Home) is my "index" page. It has some content (like a tagline), but now I want my last post to be displayed bellow that content.
Like this (front-page.php):
<?php
/*
Template Name: Front Page
*/
get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?> <--this is the tagline of my main page
<div class="line2"></div>
<?php endwhile; ?>
<<<<<<MY LAST POST HERE>>>>>>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Upvotes: 4
Views: 12267
Reputation: 2558
Use get_posts()
and do a basic loop to output the title, content or whatever you like, it will work just like a regular loop, for example..
<?php
/*
Template Name: Front Page
*/
get_header(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?> <--this is the tagline of my main page
<div class="line2"></div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
<!-- Start latest post -->
<?php $latest_post = get_posts( 'numberposts=1' ); // Defaults args fetch posts starting with the most recent ?>
<?php foreach( $latest_post as $post ) : setup_postdata( $post ); ?>
<?php the_title(); ?><br />
<?php the_content(); ?>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
<!-- End latest post -->
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Reference for functions used in the above.
http://codex.wordpress.org/Template_Tags/get_posts
http://codex.wordpress.org/Function_Reference/wp_reset_query
Hope that helps.. :)
Upvotes: 9