Wednesday, February 3, 2010

Including content from Blogger posts in another web page.

If you want to include the content of your blogger posts in another page the easiest way is with PHP.

This is the code I used to pull the data out:

<?php $url = "http://blogname.blogspot.com/index.html";
$content = file_get_contents($url);
$start = strpos($content,'<!-- google_ad_section_start(name=default) -->');
$end = strpos($content,'<!-- google_ad_section_end -->',$start);
$mycontent = substr($content,$start,$end-$start);
echo ($mycontent);
?>

Then I manipulated its formatting using CSS.

It works, but exactly where you look for the beginning and end of posts will depend on the blogger template you are using.

2 comments:

  1. Thanks. Good info. Unfortunately, my host provider has this functionality (using a remote url with file_get_contents) disabled. :(

    ReplyDelete
  2. I think my host does too (by default) and I had to override that with a local php.ini file. This was at work so I can't go in and have a look from home to see how I did it.

    ReplyDelete