WP > Static Page and latest Posts

I wanted to have a static home page top area and the latest posts below. Somehow, WordPress does not seem to have that by default. So here is my workaround:
I created a new page template in my theme folder, mytemplate.php (see code below).
Then I created a page named SiteHome using this template and another page with the default template called “Home” that is included by the template. VoilĂ .
As I don’t list the pages in the sidebar, they don’t appear separately. But if you do, you could also include a specific post into the “static header”.

<?php
/*
Template Name: MEINZTop
*/
?>

<?php get_header(); ?>
<div id="content" class="narrowcolumn">

<?php
$mypage = get_page_by_title('Home');
# print_r($mypage);
echo "<h1>".$mypage->post_title."</h1>";
echo "<p>".$mypage->post_content."</p>";
?>

<h1>Latest Posts</h1>
<?php
$lastposts = get_posts('numberposts=3');
foreach($lastposts as $post) :
setup_postdata($post);
?>
<h3><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>

<?php #the_excerpt(); ?>
<div class="entry">
<?php
echo substr(get_the_content(),0,256);
if (substr(get_the_content(),256)) {
echo "<br><a href=\"";
the_permalink();
echo "\">[...more...]</a>";
}
?>
</div>

<?php endforeach; ?>

</div>
</div><!-- page -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Leave a Reply