PDA

View Full Version : wordpress plugin to display recent posts



Chris
12-09-2006, 12:40 PM
There are vbulletin plugins/hacks to display the recent forum posts on a non vb page, such as this site's homepage.

I'm looking for the same thing for wordpress. In my searches I'm just finding wordpress plugins to change your wordpress homepage. I'm looking for something to add automatically to a non-wordpress page.

I could code it myself from the database. Or I could code an RSS parser to take it from my own RSS feed, but this has to be already coded somewhere. Anyone know?

Blue Cat Buxton
12-12-2006, 02:30 AM
I looked for this a while back and don't think it exists.

In the end I used the RSS option, which works well enough for me.

This is the code I used, with credit shown for the orignal author:





<?php

/*##############################################

RSS parser written for bMachine feed.
This script can be used to read ANY kind of RSS feeds from anywhere!


*--------------------------------------------*
Written by Kailash Nadh,
http://bnsoft.net , kailash@bnsoft.net

Author of bMachine, http://boastology.com

I wrote this script on the 1st day I studied
XML by running through the documentation at www.php.net ;)
*--------------------------------------------*

WARNING!: This script is Heavily commented! :)


This is how the script works.
> Reads the XML file
> Parses it into an array using xml_parse_into_struct()
> Converts that array into a more sensible, easily usable array
[ See the structure.txt file to get an idea of the array structure ]
> Finally, Display the data in anyway you want!

This script demonstrates the use of simple logic
to do Complex XML/RSS parsing functions
This script can be easily developed into a powerful application.

##############################################*/

global $data;


// Enter the url to an RSS feed
$url="http://news.bbc.co.uk/rss/newsonline_uk_edition/world/rss.xml";

$file = $url;
$ch = curl_init($file);
$fp = @fopen("temp.xml", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$file = "temp.xml";
//$fp = fopen($file, "r");
//$data = fread($fp, 1000);




$data=@fread(fopen($file,"r"),10000) or die("Cant open $url!");

// Get the file contents

$myar=getXmlData($data);
// What ever it may be, the argument to this
// function should be the XML document's content


// Now $myar holds the fully parsed XML contents.
// It may have a number of tags, like <TITLE> , <LINK> , <AUTHOR> , <SOMETHING> ... and so on
// With a simple loop, you can extract all the tags and their values neatly

// Remember, $i<= should be lesser than or equal to the number of values
// a tag has. If you give count($myar), it will only take the number of tags.
// See structure.txt for better understanding.


for($i=0;$i<=count($myar[TITLE]);$i++) {

// Here, we want to read the TITLE, DESCRIPTION, and LINK of the RSS feed.
// You can read the values of any tag like this.
// $myar[TITLE][$i], $myar[SOMETHING][$i], $myar[SOMETAG][$i].... and so on..
// Here it goes

$title=$myar[TITLE][$i+1];
$text=$myar[DESCRIPTION][$i];
$link=$myar[LINK][$i+1];

if($title) {
if ($i>=0 and $i<3)
{
echo <<<EOF
<a href="$link"><font size="2" face="Verdana" color="blue">$title</font></a><br>
<font size="2" face="Verdana">$text</font><br><br>
<hr width="100%" size="1" align="left">
EOF;
}
}

}



//################################################## ###################

// This is the function. It returns the array of the parsed XML data

function getXmlData($xml_doc) {

//echo "xml_doc is ";
//echo $xml_doc;

$n=0; // Counter used for arraying the XML data
$ar=array(); // The main array for storing parsed xml using xml_parse_into_struct()

// Parse the XML document

$parser = xml_parser_create();
//$simple = "<para><note>simple note</note></para>";
$simple=$xml_doc;
//echo $simple;

xml_parse_into_struct($parser,$simple,$vals,$index );
// or die(xml_error_string(xml_get_error_code($parser))) ;
xml_parser_free($parser);


$ttags=array(); // Temporary arry for storing tag names


// The main part. This is MY CREATION
// and this piece of code makes this script simple :)
// This is the "MAGIC LOOP" !! :)

for($n=0;$n<=count($vals)-1;$n++) {
if(trim($vals[$n][value])) {
$ar[$vals[$n][tag]][count($ar[$vals[$n][tag]])]=$vals[$n][value];
$ttags[$vals[$n][tag]]=$vals[$n][tag];
}
}


// Array for storing all the tag names
// This array will hold all the Tag names found in the XML document
// eg: ("TITLE","LINK","AUTHOR","DOMAIN")..
// Use this if you need it.

$tags=array();

// Extract and save the tag names to the array
foreach($ttags as $tagi) { array_push($tags,$tagi); }

return $ar;

}

?>

Chris
12-12-2006, 06:49 AM
Nifty, thanks.

Dan Grossman
01-02-2007, 01:28 AM
Have you taken a look at FeedBurner (http://www.feedburner.com)? In addition to giving you all kinds of information about the circulation and usage of your feed, they have tons of tools for working with the feed, from automatically converting it into every reader's preferred format (RSS 1/2/ATOM), showing it in HTML format when viewed through a browser, to a bit of JavaScript to syndicate the feed as HTML (like you're looking for) called BuzzBoost.