Haven't been doing much web stuff for a while. Pick up again this time around.
I tried to implement this blog site to my own website. After searching Google for a while, all I found were ways to import WordPress to Blogger or vice versa. All those tasks could be done by features WordPress and Blogger have provided.
But how do I import to my own website? Time to take a look at RSS feed Blogger gives us.
Copy RSS feed url from Blogger. It is under Settings->Other, I have my burned with Feedburner, therefore my RSS feed shows as a feeds.feadburner.com url.
To load RSS feed with PHP, use simplexml_load_file. $xml = simplexml_load_file('http://YOUR_FEED_URL');
Create a php page with code below
<?php
$xml = simplexml_load_file('YOUR_FEED_URL');
print_r($xml);
?>
print_r($xml) will print everything RSS feed xml file contains, but it will be hard to read once it prints in the web browser.
Here is a trick to make it more user friendly to view. view its source code. It will show in a file structure format.
First section of this code starts with ID, updated date and Tags. Title, stitle, author and other information follows afterward.
To query and display these data onto the website, just use $xml->title, $xml->stitle, etc.
There are couples items inside author: name, uri and email. They can be called by $xml->author->name, $xml->author->uri, and $xml->autor->email
Entry is where all the published blogs can be found.
Using PHP to put all blog entries into a loop as:
<?php
foreach ( $xml->entry as $entry ) {
echo '<a href="'. entry->link[4]['href'] .'" target="_blank">'.
$entry->title .'</a>'. $entry[0]->published .'<br />'. $entry->content ."\n";
}
?>
link[4]['href'] displays attribute for XML data. Use this format whenever seeing [@attributes]=>array, or [0], [1]...
Any other data from XML can be import as the same format.
Apply personal designed CSS style sheet, my blog is sitting within my website.
--------------------------
个人网页(Personal Website):http://xiangstan.com
Facebook:http://www.facebook.com/xiangs.tan
No comments:
Post a Comment