Revision: 53629
Updated Code
at December 2, 2011 04:59 by stephcode
Updated Code
<?php
// Include WordPress
define('WP_USE_THEMES', false);
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
$words = explode(' ', $string);
// 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
return implode(' ', array_slice($words, 0, $word_limit));
}
?>
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>
Revision: 53628
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 30, 2011 04:58 by stephcode
Initial Code
<?php
// Include WordPress
define('WP_USE_THEMES', false);
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
$words = explode(' ', $string);
// 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
return implode(' ', array_slice($words, 0, $word_limit));
}
?>
Then, replace <?php the_excerpt(); ?> with:
<?php echo limit_words(get_the_excerpt(), '10'); ?>
Initial URL
http://css-tricks.com/snippets/wordpress/run-a-loop-outside-of-wordpress/
Initial Description
Put the following outside WP
Initial Title
Run a loop outside WordPress installation
Initial Tags
wordpress
Initial Language
PHP