Lewis Bilsland Design

Illustration

T-Shirt concept artwork

blog

Read more function

I decided to place some excerpts on my home page, this helps give users an insight to the blog before clicking through, it’s something that gives a reader more choice which can’t be a bad thing.

To do this you need to insert the following code into your function.php file, there is a part of the code where you can design your own arrow or more link button:

add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {

return 35; }
//function to replace invalid ellipsis with text
function elpie_excerpt($text)
{

return str_replace('[...]', '<a href="'.get_permalink().'"><img src="yourpathhere/readmore.jpg" alt="" /></a>', $text);
}
add_filter('the_excerpt', 'elpie_excerpt');

Now all you need to do is edit your page template to include the following code, you can wrap with a css style to colour the fonts, rollovers etc:

<ul id="recent-items">
<ul>
<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=2');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><br /><?php the_excerpt(); ?></li>
<?php endwhile; ?>
</ul>
</ul>

January 26, 2010 Posted by Lewis Wordpress, php No Comments »

Leave a Reply


RSS Feed
Follow me on twitter