Announcement

Collapse
No announcement yet.

Adding RSS Feed in PHP Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Adding RSS Feed in PHP Code

    HI, I am currently trying to add an RSS news feed into my website and I want to show it on my front page only.

    The code is in PHP code and i can not get it to work.
    Is there a way to add this code to My site to show either on the top of my front page or in a seperate Brochure page and if so, how and where can I paste it?

    This is the code I want to paste into a page on my website,

    <?php
    $olderror_reporting =error_reporting(0);
    include ("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Fnewsrss.bbc.co.uk%2Frss%2Fnewsonline_uk_edition%2Ffront_page%2Frss.xml,http%3A%2F%2Fnewsrss.bbc.co.uk%2Frss%2Fnewsonline_uk_edition%2Fhealth%2Frss.xml&newpage=1&chead=1&atl=1&desc=1&owncss=&eleminate=&auth=1&dts=1&width=300&max=8&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=1&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$HTTP_SERVER_VARS['SERVER_NAME'].$HTTP_SERVER_VARS['PHP_SELF']."&phpout=1");
    error_reporting($olderror_reporting);
    ?>

    Many thanks
    Simon

    #2
    The PHP for the rss feed will need to run on the server. Often servers are set up to only run PHP on pages with a .php extension as this saves the server from having to parse all web pages for any php code.

    If your server is set up this way then you might need to create a page with a .php extension.

    Actinic also do a free rss feed script in php. This might be easier to integrate but I haven't tried it.

    Mike
    -----------------------------------------

    First Tackle - Fly Fishing and Game Angling

    -----------------------------------------

    Comment


      #3
      will saving the page as a php not a html file in actinic work?

      Comment


        #4
        It might well do. I seem to remember seeing that actinic pages can now have the .php extension.

        I don't know if this will fix the problem as we haven't been told yet what the problem is.

        Mike
        -----------------------------------------

        First Tackle - Fly Fishing and Game Angling

        -----------------------------------------

        Comment


          #5
          You could apply an .htaccess rule to serve php extension as .html - therefore you set your homepage or brochure page to be called filename.php - your server parses the data as php yet the front end shows filename.html - so you won't have to set up redirects from filename.html to the new filename.php

          Comment


            #6
            Originally posted by olderscot View Post
            It might well do. I seem to remember seeing that actinic pages can now have the .php extension.

            I don't know if this will fix the problem as we haven't been told yet what the problem is.

            Mike
            Not sure what the problem is, Im only just learning a bit about HTML etc and not really sure what im doing with it.
            PHP code know nothing about.
            I entered the code given in Java and works fine.
            All i did was paste it into one of the design code html like the java code but nothing happend and did not show any changes.

            I have read that Java is egnored by search crawls and spiders etc but will pick up and spider the site more offen with rss in PHP code.
            Hence why i would like to input it in PHP Code instead.

            Comment


              #7
              So what happens on the page with the php code? Does it display the php code on the page?

              have you a page where we can look at your efforts? It might help identify the problem.

              Mike

              PS. Another forum member recently posted that the rss feed wouldn't display with logged in customers. Are you using customer accounts?

              PPS. Simon, I can see Google are showing Sainsbury's ads on your website. Are you sure you like this?
              -----------------------------------------

              First Tackle - Fly Fishing and Game Angling

              -----------------------------------------

              Comment


                #8
                Also looked into this recently, and it was not possible with our website host to allow .xml pages to be parsed as PHP.

                So in the end I wrote a script that is run to produce the xml file in the desired location. So, for example, batch_xml_generator.php produces rss.xml.

                You could get a cron job to run at regular intervals to run batch_xml_generator.php.

                Code:
                #!/usr/local/bin/php -q
                <?php
                
                db_connect($hostname, $username, $password, $databasename);
                	
                	define("NEWS_XML_FILE", "/path/to/your/xml/file/news.xml");
                
                	$myFile = NEWS_XML_FILE;
                	$fh = fopen($myFile, 'w') or die("can't open file");	
                		
                	$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                		."<rss version=\"2.0\">\n"
                		."<channel>\n"
                		."<title>Our News</title>\n"
                		."<link>http://www.yourdomain.com/</link>\n"
                		."<description>Our description</description>\n"
                		."<language>en</language>\n"
                		."<category>Your categories</category>\n";
                		
                	fwrite($fh, $header);
                		
                	$sql = "select
                	
                				title,
                				description,
                				link,
                				DATE_FORMAT(pubDate, '%a, %d %b %Y %H:%i:%s') as pubdate
                	
                				from
                				
                				db_news_table
                				
                				order by pubdate desc
                				
                			";
                				
                	$result = mysql_query($sql);
                	$numRows = mysql_num_rows($result);
                	
                	for($i=0; $i < $row = mysql_fetch_array($result); $i++){
                	
                		$item = "<item>\n"
                			."<title>".$row['title']."</title>\n"
                			."<description>".$row['description']."</description>\n"
                			."<link>".$row['link']."</link>\n"
                			."<pubDate>".$row['pubdate']."</pubDate>\n"
                			."</item>\n";
                			
                		fwrite($fh, $item);
                	
                	}
                	
                	$footer = "</channel>\n"
                		."</rss>\n";
                		
                	fwrite($fh, $footer);
                	fclose($fh);
                
                ?>
                HTH

                Comment


                  #9
                  Originally posted by olderscot View Post
                  So what happens on the page with the php code? Does it display the php code on the page?

                  have you a page where we can look at your efforts? It might help identify the problem.

                  Mike

                  PS. Another forum member recently posted that the rss feed wouldn't display with logged in customers. Are you using customer accounts?

                  PPS. Simon, I can see Google are showing Sainsbury's ads on your website. Are you sure you like this?
                  NO it dose nothing. When I put the java in the same place it puts the square box in the place. But when i paste the PHP code, there are no changes at all.

                  Comment


                    #10
                    Can you show us the page where this is? It would if we could see the code in action (or not).

                    Mike
                    -----------------------------------------

                    First Tackle - Fly Fishing and Game Angling

                    -----------------------------------------

                    Comment


                      #11
                      This is the file that is generated from a MySQL database of news (currently 1 item!):

                      http://www.locksonline.com/rss/locksonline_news.xml

                      The same data also produces the following page:

                      http://www.locksonline.com/acatalog/news.html

                      If anyone wants the SQL to generate the DB table, give me a shout.

                      Comment


                        #12
                        Originally posted by olderscot View Post
                        Can you show us the page where this is? It would if we could see the code in action (or not).

                        Mike
                        Boody hell now i cant get back into it.
                        Normly i just click the mouse on the top section box and the code comes up for that box, then i edited the cox details.
                        Now it wont work and dont know how to get back in there, i wont let me click on it in the preview as I normaly do.
                        Like I say learning here.
                        Hold on while i figer a way to get back in there,

                        Comment


                          #13
                          Originally posted by olderscot View Post
                          Can you show us the page where this is? It would if we could see the code in action (or not).

                          Mike
                          ok found it, here is where I have now for the moment put a google code that works but i think its in java no?

                          <actinic:block if="%3cactinic%3avariable%20name%3d%22FragmentAnchor%22%20%2f%3e%20%21%3d%20%22%22" >
                          <a name="<actinic:variable name='FragmentAnchor' />"></a>
                          </actinic:block>
                          <tr>
                          <td valign="top" align="center">

                          <table width="100%" cellspacing="0" cellpadding="10" border="0">
                          <tr>
                          <td valign="top" align="center">
                          <iframe frameborder="0" width="610" height="120" marginwidth="0" marginheight="0"
                          src="http://www.google.com/uds/modules/elements/newsshow/iframe.html?topic=h,w,m&ned=uk&rsz=large&hl=en&format=500x120">
                          </iframe>
                          <actinic:variable name="FragmentImage" />
                          </td>
                          </tr>
                          </table>

                          The red is the code, now I will give you the code with the PHP code

                          <actinic:block if="%3cactinic%3avariable%20name%3d%22FragmentAnchor%22%20%2f%3e%20%21%3d%20%22%22" >
                          <a name="<actinic:variable name='FragmentAnchor' />"></a>
                          </actinic:block>
                          <tr>
                          <td valign="top" align="center">

                          <table width="100%" cellspacing="0" cellpadding="10" border="0">
                          <tr>
                          <td valign="top" align="center">
                          <?php
                          $olderror_reporting =error_reporting(0);
                          include ("http://rssfeedreader.com/rss3/rss.php?url=http%3A%2F%2Fnewsrss.bbc.co.uk%2Frss%2Fnewsonline_uk_edition%2Ffront_page%2Frss.xml,http%3A%2F%2Fnewsrss.bbc.co.uk%2Frss%2Fnewsonline_uk_edition%2Fhealth%2Frss.xml&newpage=1&chead=1&atl=1&desc=1&owncss=&eleminate=&auth=1&dts=1&width=300&max=8&tlen=0&rnd=1&bt=3&bs=Double&nmb=&ntb=&naf=&nst=&nwd=0&nht=0&dlen=0&lstyle=-1&lc=Blue&bg=White&bc=Gray&spc=&ims=1&tc=&ts=11&tfont=Verdana,+Arial,+Sans-serif&rf=".$HTTP_SERVER_VARS['SERVER_NAME'].$HTTP_SERVER_VARS['PHP_SELF']."&phpout=1");
                          error_reporting($olderror_reporting);
                          ?>
                          <actinic:variable name="FragmentImage" />
                          </td>
                          </tr>
                          </table>

                          It says on there (Copy / Paste the code below to your web pages to embed the RSS Feed
                          for the search engines. )
                          Is this correct?

                          Comment


                            #14
                            It says on there (Copy / Paste the code below to your web pages to embed the RSS Feed
                            for the search engines. )
                            Is this correct?
                            Probably.

                            What I was looking for is to see the code live on your website so I could take a look at what's happening to try and work out why it isn't working.

                            Any chance you could make the change and upload to your website.

                            Mike
                            -----------------------------------------

                            First Tackle - Fly Fishing and Game Angling

                            -----------------------------------------

                            Comment


                              #15
                              Originally posted by olderscot View Post
                              Probably.

                              What I was looking for is to see the code live on your website so I could take a look at what's happening to try and work out why it isn't working.

                              Any chance you could make the change and upload to your website.

                              Mike
                              OK cool, no problem, give me a few minutes and i will enter the code and upload it to the live site. Ill leave a message here when ive done it

                              Comment

                              Working...
                              X