/ Published in: PHP
Put the following outside WP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // Include WordPress require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php'); query_posts('showposts=1'); ?> <?php while (have_posts()): the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_excerpt(); ?> <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p> <?php endwhile; ?> To truncate excerpt, put this inside functions.php, inside WP theme: <?php function limit_words($string, $word_limit) { // creates an array of words from $string (this will be our excerpt) // explode divides the excerpt up by using a space character // this next bit chops the $words array and sticks it back together // starting at the first word '0' and ending at the $word_limit // the $word_limit which is passed in the function will be the number // of words we want to use // implode glues the chopped up array back together using a space character } ?> Then, replace <?php the_excerpt(); ?> with: <?php echo limit_words(get_the_excerpt(), '10'); ?> Alternatively: http://www.webdesigncreare.co.uk/blog/videos/recent-posts-outside-wordpress.html <ul> <?php require($_SERVER['DOCUMENT_ROOT'] . '/wordpress/wp-load.php'); query_posts('showposts=3'); if (have_posts()) : while (have_posts()) : the_post(); ?> <li> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <span>Posted on <?php the_time('l jS F, Y') ?></span><br /> <?php the_excerpt(); ?> </li> <?php endwhile; else: echo "no posts"; endif; ?> <?php wp_reset_query(); ?> </ul>
URL: http://css-tricks.com/snippets/wordpress/run-a-loop-outside-of-wordpress/