how to display wordpress posts on a non-wordpress website:
PHP method found here - http://w-shadow.com/blog/2008/11/15/displaying-recent-posts-on-a-non-wordpress-page/
1. Download SimplePie
2. Grab the simplepie.inc file and put it somewhere on your server
3. Put this code in a php file:
<?php
$feed_url = 'http://w-shadow.com/feed/';
$max_items = 5;
//Load SimplePie
include 'includes/simplepie.inc';
//Fetch the RSS feed
$feed = new SimplePie($feed_url);
//Check for errors
if ($feed->error())
echo 'Error : ',$feed->error();
//Output up to $max_items posts
foreach ($feed->get_items(0, $max_items) as $item): ?>
<div class="item">
<h3 class="title"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h3>
<?php echo $item->get_description(); ?>
<p><small>
Posted <?php if ($author = $item->get_author()){ echo ' by '.$author->get_name(); }?>
on <?php echo $item->get_date('j F Y | g:i a'); ?>
</small></p>
</div>
<?php
endforeach;
?>
*I also turned off cache in the include file. If you don't want to do that, you need to create a cache folder.
PHP method found here - http://w-shadow.com/blog/2008/11/15/displaying-recent-posts-on-a-non-wordpress-page/
1. Download SimplePie
2. Grab the simplepie.inc file and put it somewhere on your server
3. Put this code in a php file:
<?php
$feed_url = 'http://w-shadow.com/feed/';
$max_items = 5;
//Load SimplePie
include 'includes/simplepie.inc';
//Fetch the RSS feed
$feed = new SimplePie($feed_url);
//Check for errors
if ($feed->error())
echo 'Error : ',$feed->error();
//Output up to $max_items posts
foreach ($feed->get_items(0, $max_items) as $item): ?>
<div class="item">
<h3 class="title"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h3>
<?php echo $item->get_description(); ?>
<p><small>
Posted <?php if ($author = $item->get_author()){ echo ' by '.$author->get_name(); }?>
on <?php echo $item->get_date('j F Y | g:i a'); ?>
</small></p>
</div>
<?php
endforeach;
?>
*I also turned off cache in the include file. If you don't want to do that, you need to create a cache folder.
No comments:
Post a Comment