Jump to content

Displaying My Blog Feed


millsy007

Recommended Posts

I have a wordpress blog in a subdirectory of my site, I want to keep it seperate from the rest of my site, but would like to access the latest posts on my sites homepage.

 

I am trying to do this by reading the blog feed and displaying it but the code I have found relies on a wordpress function, but as I have this installed on a different section of my site I cant access that functionality. Is there a way I could modify the following to get out what I need?

 

<?php
require_once(ABSPATH . WPINC . '/rss-functions.php');
$rss = fetch_rss('http://www.mysite.nl/blog/rss');
echo '<ul>';
for($i=0;$i<5;$i++) {
$item=$rss->items[$i];
echo '<li><a href="' . $item['link'] . '" title="' . $item['title'] . '">' . $item['title'] . '</a></li>';
}
echo '</ul>';
?>

Link to comment
https://forums.phpfreaks.com/topic/136511-displaying-my-blog-feed/
Share on other sites

You could pull the posts from the wordpress database with code something like this:

<?php
$query = "
SELECT 
	post_date, 
	post_title, 
	post_content, 
	guid 
FROM 
	`wp_posts` 
ORDER BY 
	post_date DESC 
LIMIT 
	0,5";
$result = mysql_query($query);
foreach ($post = mysql_fetch_object($result)) {
?>
<div class="post">
	<div class="post_title">
		<a href="<?= $post->guid ?>"><?= $post->post_title ?><span class="pdate"><?= $post->post_date ?></span></a>
	</div>
	<div class="post_content"><?= $post->post_content ?></div>
</div>
<?
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.