In order to pull a set number of words use:
1 2 3 4 5 6 7 8 9 10 |
<?php require($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php'); $args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date"); $postslist = get_posts( $args ); echo '<ul id="latest_posts">'; foreach ($postslist as $post) : setup_postdata($post); ?> <li><strong><?php the_date(); ?></strong><br /> <a href="<?php the_permalink(); ?>" title="<?php the_title();?>"> <?php the_title(); ?></a><br><?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) );?> </li> <?php endforeach; ?> </ul> |
Calling “wp-blog-header.php” is needed in order to have the wordpress functions available.
If you prefer to pull a fixed number of characters then “substr()” is needed – to avoid cutting a word in the middle you could search for the last space character from the end of the string.