Page 1 of 2 12 LastLast
Results 1 to 15 of 20

Thread: How to implement "recent blog posts" on home page?

  1. #1
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147

    Question How to implement "recent blog posts" on home page?

    My question is very quick...

    I see that this site has a section that automatically updates itself and lists "recent blog posts" on the home page.

    How is this done?

    Note: My blog is hosted separately form my site (through Blogger).


    Thanks...

  2. #2
    Registered
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    99
    If you want to go the PHP route, try SimplePie.

  3. #3
    Not that blue at all Blue Cat Buxton's Avatar
    Join Date
    May 2004
    Location
    UK
    Posts
    932
    I use the script here... http://boastology.com/pages/mods.php ... the one at the bottom

    You can see it in action here (slightly modified output) http://www.cameraphonereview.co.uk towards the bottom under latest cameraphone news

    It works with different domains, so should fit the bill.

    I also just looked at simplepie, but the demo did not seem to be working.

  4. #4
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    I use a generic RSS posting script. IT takes any RSS feed and can post it, I modified it as needed and just feed my blog's rss feed to it.

    That type of setup will work for any blog, remotely hosted or otherwise.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  5. #5
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Thanks, everyone...

    Before I do any work on this, one more quick question.

    Since my blog is remotely hosted, am I doing my main site a disfavor by having these outgoing links now? I know some of the PR will get sent back to my main site (page) because the blog has links to it, but I also know that some of the PR still gets lost.

    So, do I stand to gain more form having this feature, than I stand to lose by leaking part of my PR?

    What would be the general opinion on this issue?

    Thanks...

  6. #6
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    I wouldn't worry.

    Your blog is remotely hosted, but that doesn't mean you do not control it. PageRank flows irregardless of domain, and in the grand scheme of things your blog will function, for PR flow, as if it were not remotely hosted and just another part of your site. Assuming you'll of course have links from your blog back to your site.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  7. #7
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    I'm afraid I'm not able to make any progress on this.

    I looked at SimplePie but the whole thing was just confusing and unclear to me. I don't see any clear instructions on that site, that would tell me how to do this.

    I downloaded http://boastology.com/pages/mods.php as Blue Cat Buxton suggested. I would really like to make this work, but there are absolutely no instructions for non-programmer like myself. It says the script is heavily commented, but to me its all Greek. There is one line that says "Enter the url to an RSS feed". I entered my feed's URL there. Then I uploaded that scrip to my server and tried to access it with my browser, to see what happens, and all I got was an error message. In any event, I would like to have the last posts of my blog appear on my home page, which is a static HTML page, and there are no instructions that explain how to do that (and I read all the comments in the script).

    I also did a Google search for "RSS posting script" as Chris suggested, but wasn't able to make any sense of anything I found.

    I'm kind of stuck...

    Any help...?

  8. #8

  9. #9
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Thanks for looking into this.

    The error message is "unclosed token".

    The script is this:

    Code:
    <?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.
    
    ##############################################*/
    
    
    
    $url="http://feeds.feedburner.com/cardshark";
    	// Enter the url to an RSS feed
    
    $data=@fread(fopen("$url","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];
    $text=$myar[DESCRIPTION][$i];
    $link=$myar[LINK][$i];
    
    	if($title) {
    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="50%" size="1" align="left">
    EOF;
    	}
    
    }
    
    
    
    //#####################################################################
    
    // This is the function. It returns the array of the parsed XML data
    
    function getXmlData($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();
    xml_parse_into_struct($parser,$xml_doc,$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;
    
    }
    
    ?>
    I changed line 37 so that it has the URL of my feed.

    The script is currently uploaded here:

    http://cardshark.us/scripts/rss-reader.php

    Thank you for your time...

  10. #10
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    This is the script I use... I think...

    http://magpierss.sourceforge.net/

    Modded of course. And obviously I could do better with special character encoding. Whatever. I actually don't 100% recall where I got it, But I think it is Magpie.

    Here is the code

    PHP Code:
      <?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://www.websitepublisher.net/blog/feed/"

    //$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("http://www.websitepublisher.net/blog/feed/","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]; 
    $link=$myar[LINK][$i+1]; 

        if(
    $title) { 
        if (
    $i>=and $i<6)    { 
    echo 
    "<li><a href=\"".$link."\">".$title."</a></li>"

        } 





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

    // 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 Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  11. #11
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    ...haha, you have the same script.

    So, that is exactly what I use on this site, and it works. If you change the URLs you should be fine. Or maybe your webserver has an odd setting that is breaking it.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  12. #12
    Registered
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    99
    That script is way bad PHP.

    The error message that its giving you is that your XML is bad. My guess is that your feed is too big for the simple fread function the way its used in that script. Hence, "unclosed tokens" because its only reading the first part of the feed.

    You really should use SimplePie.

    If thats the only bug in that script, I'd be surprised.

  13. #13
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Thanks for your reply, Chris.

    I guess I made some progress...

    I copied the script that Chris posted and changed two URLs. Now the script looks like this:

    PHP Code:
    <?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://feeds.feedburner.com/cardshark/"

    //$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("http://feeds.feedburner.com/cardshark/","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]; 
    $link=$myar[LINK][$i+1]; 

        if(
    $title) { 
        if (
    $i>=and $i<6)    { 
    echo 
    "<li><a href=\"".$link."\">".$title."</a></li>"

        } 





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

    // 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



    ?>
    I used another name and uploaded it here:

    http://cardshark.us/scripts/rss_blog.php

    Now at least I do get a result, but the script only returns my site's title linked to my site's URL (not the blog URL).

    My feed URL is this:

    http://feeds.feedburner.com/cardshark

    I guess this is progress but now I'm kind of stuck again (I did try a few different things, though).

  14. #14
    Registered Mr. Pink's Avatar
    Join Date
    Sep 2008
    Location
    USA
    Posts
    147
    Selkirk,

    I just visited the SimplePie page again.

    My problem is that I am a bit behind on all the terminology and can't figure out where to start looking for a solution on that page.

    All I want to do is have 5 last titles on my blog to show up somewhere on my existing home page, which is a static HTML page. I think that I should just be able to add one tag to my HTML and a PHP script. But I just can't figure this out.

    I don't know how much work it is at your end, but if you could just post a script I can copy and paste that would be great.

  15. #15
    Not that blue at all Blue Cat Buxton's Avatar
    Join Date
    May 2004
    Location
    UK
    Posts
    932
    I tried your url in my version of the script - same one Chris posted - and got similar results to you, so we know it can work. What you need to do is select the headings that the script is pulling from the feed.

    that is this bit here (from Chris's script as that is working for you:

    PHP Code:

    $title
    =$myar[TITLE][$i+1]; 
    $link=$myar[LINK][$i+1]; 
    This is selecting the title and the link, which is exactly what you are getting.

    try including:

    PHP Code:
    $description=$myar[DESCRIPTION][$i+1]; 
    and then add below the echo statement underneath:

    PHP Code:
    echo $description
    If you look at the source of the feed, ie direct at http://feeds.feedburner.com/cardshark you should see the other fields you can get from the feed.

Similar Threads

  1. Is any other method to get Website PR ?
    By number7 in forum Search Engine Optimization
    Replies: 10
    Last Post: 01-08-2019, 03:33 AM
  2. PR3 Directory - $20/yr home page link
    By webdexed in forum The Marketplace
    Replies: 1
    Last Post: 09-30-2007, 02:48 PM
  3. [turnkey] Lyrics site - $149 (LEGAL)
    By rightinpoint in forum The Marketplace
    Replies: 1
    Last Post: 10-22-2006, 02:21 AM
  4. Home page not indexed?
    By Westech in forum Search Engine Optimization
    Replies: 16
    Last Post: 10-18-2004, 02:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •