0

I'm building a custom html website from the ground up and one of my navigation tabs at the top is called "blog". Instead of populating that tab with content created in my code, I'd like to populate it with content that is maintained externally (for example blogger or WordPress or some easy blog formatting tool).

Can't seem to figure out an easy way to embed my externally maintained blog into my website. If at all possible, I'd like for the embed to be responsive, customizable, and searchable. Any ideas?

A.C.
  • 15
  • 1
  • 5

1 Answers1

0

If you want to embed code from another site into your own site, you have to 1) link it in OR 2) retrieve and parse it.

1) The typical solution for this was iframe. It's not simple, but you can use the width and height settings for the iframe with @meda css queries to obtain a measure of responsiveness.

2) If you have php as a tool, you can look at this stack overflow answer to get an idea how to retrieve the website code, then parse the code out.

for instance, if I wanted only the information after the closing head tag, I could do

// get the webpage source -- depends on allow_url_fopen
// see the previously mentioned stack overflow answer for alternates
$externalWebpage = file_get_contents('http://yoursite.com/your-page.html');

// split the webpage by </head>
$websiteSections = explode($externalWebpage, '</head>',);

// don't neglect to add the '</head>' back if you want to use that 
// portion somewhere else
$head = $websiteSections[0] . '</head>';
$body = $websiteSections[1];

Assuming you went with the php solution, all this could be done in the backend of the site prior to generating the html. Further parsing is obviously possible, but depends on your knowledge of the external page's structure.

Community
  • 1
  • 1
Ken Sherman
  • 279
  • 1
  • 2
  • 9
  • Thanks Ken! Yes I experimented with iframe but it just didn't look good with my website (couldn't style it). Your php solution looks great. Because my coding knowledge is basic, I was hoping for some code generator (like "embedly") to do the work for me. But I wasn't able to get the blog posts to show up using embedly's generated code. If I can't find an easier solution I will have to brush up on my php and have a go at it. Thanks. – A.C. May 20 '16 at 18:32