Jump to content

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>
<?
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.