Friday, April 24, 2009

displaying a teaser or excerpt with read more in wordpress

In my previous post I was working on how to limit the number of post on worpress the code below also does the same thing but let me explain them line by line.


<?php $my_query = new WP_Query('category_name=f_art&showposts=50');

while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>



<?php the_content('Read More...', strip_teaser, 'more_file'); ?>

<?php endwhile; ?>


THE CODE BY LINE

<?php $my_query = new WP_Query('category_name=f_art&showposts=50');
This code calls for a specific category name which is f_cart and will display 50 posts maximum if you remove the &showposts and of course the equal sign and the number; this will display all posts categorized under the category slug f_art.


while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
Here we have three lines of code I guess this is quite straight forward this will just display the post title which is also a link under the category specified before it.

<?php the_content('Read More...', strip_teaser, 'more_file'); ?>
This line tells wordpress to display the post or article under the category specified above it, what is more it displays a read more link if you need an excerpt or teaser. There is actually a more button on the wordpress admin. If you are adding or editing a post look above the wysiwig editor you should find this image:





Just look for a desired point in your post where you want to add the more link and click on the button. This link is a further explanation http://codex.wordpress.org/Customizing_the_Read_More.

No comments:

Post a Comment