You are reading Homepage Template. You can leave a comment or trackback this post.
Posted on August 2nd, 2006 by mark.
Categories: WordPress.
This is a description of a customised WordPress homepage template for a static home page with the static text at the top and a dynamic section underneath with excerpts of the latest 3 news posts.
The template name is at the start of the template:
<?php
/*
Template Name: Homepage
*/
?>
Get the header and sidebar:
<?php get_header(); ?>
<?php get_sidebar(); ?>
Use the CSS style for - div ID "contentcontainer" - then start the loop:
<div id="contentcontainer">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
This section of code delivers the first section of text on the home page in the first text box the first line and the last line start and end the text box:
<div class="blogbefore"></div> <div class="blog"><div class="overflow: hidden;"><h3><a xhref="<?php the_permalink(); ?>" title="Permalink for <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<p class="headertext"><?php the_content(); ?>
<?php if(!is_single()) { ?><p class="footertext"><?php comments_popup_link('0 comments.', '1 comment.', '% comments.' ); ?></p><? } else { ?><p class="footertext"><?php comments_number(__('0 comments.'), __('1 comment.'), __('% comments.')); ?></p><?php } ?>
</div></div>
<div class="blogafter"></div>
The next section is the code for the dynamic section which will take titles and excerpts from the first 3 posts from the general news catagorythe first line and the last line start and end the text box:
<div class="blogbefore"></div> <div class="blog"><div class="overflow: hidden;"><h3><a xhref="http://www.markgibson.info/index.php?cat=2"> Latest News</h3><p class="headertext"></p> <?php $my_query = new WP_Query('category_name=general-news&showposts=3'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <h4><a xhref="<?php the_permalink(); ?>" title="Permalink for <?php the_title(); ?>"><?php the_title(); ?></a></h4> <?php the_excerpt(); ?>
<?php endwhile; ?>
</div></div>
<div class="blogafter"></div>
The last section of code covers the end of the loop and the end of the template:
<?php comments_template(); ?>
<?php endwhile; else: ?><div class="blogbefore"></div>
<div class="blog">
<h3>There are no blogs relating to your query.</h3>
</div>
<div class="blogafter"></div><?php endif; ?>
</div>
<?php get_footer(); ?>
0 comments.
Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.