Posted by on March 19, 2011

We can using an RSS feed to display our vbulletin latest threads on an external page. Let me explain how to to achieve this.

For example, we want to show forums.glassesadvisor.com latest posts at your page.

1. Add the following code to the .php page you plan to show your latest vbulletin posts.

// ######################################################
// ## configuration
// ##
// ## $rss_file= ‘http://www.discountglassesdirect.com/forums/external.php?type=RSS2’;
// ## Adjust this variable to point to your RSS feed

$rss_file = ‘http://www.discountglassesdirect.com/forums/external.php?type=RSS2’;

// ## configuration end
// ######################################################
// ## Do not touch code below!

$is_item = false;
$tag = ”;
$title = ”;
$description = ”;
$link = ”;

function character_data($parser, $data)
{
global $is_item, $tag, $title, $description, $link;
if ($is_item)
{
switch ($tag)
{
case “TITLE”:
$title .= $data;
break;
case “DESCRIPTION”:
$description .= $data;

break;
case “LINK”:
$link .= $data;
break;
}
}
}

function begin_element($parser, $name)
{
global $is_item, $tag;
if ($is_item)
{
$tag = $name;
}
else if ($name == “ITEM”)
{
$is_item = true;
}
}

function end_element($parser, $name)
{
global $is_item, $title, $description, $link, $rss_output;
if ($name == “ITEM”)
{
$rss_output .= “<dt><strong><a href='” . trim($link) . “‘>” . htmlspecialchars(trim($title)) . “</a></strong></dt><dd>” . htmlspecialchars(trim($description)) . “</dd>”;
$title = “”;
$description = “”;
$link = “”;
$is_item = false;
}
}

$parser = xml_parser_create();

xml_set_element_handler($parser, “begin_element”, “end_element”);
xml_set_character_data_handler($parser, “character_data”);
$fp = fopen($rss_file,”r”);

while ($data = fread($fp, 4096))
{
xml_parse($parser, $data, feof($fp));
}

fclose($fp);
xml_parser_free($parser);

2.Add the following code to wherever on that page you want to display the output:
echo $rss_output;

Posted in: vBulletin