1

I have (what I think is an awesome HTML page). I want to integrate the person's Facebook feed into the HTML page, but I don't want their stupid white and blue iframe box they give. The site is here.

I haven't ever made much with PHP but found a way to pull a feed from Facebook using PHP. It's on a separate page.

As I understand you can't embed PHP into HMTL directly. I'd like to pull the output of the php page and put it under //News from Facebook - but am unsure how.

I even created an index.php page if you add index.php to the end of the first link I gave.

but still can't get it to populate. I'm good with HTML but a n00b at PHP. How can I integrate the two? I just want the output to appear under //News from facebook

I already have some items in an htaccess file based on links I found online - but they don't seem to help:

Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^(.*)\.htm$ $1.html [NC]
AddType application/x-httpd-php .php .htm .html
AddHandler application/x-httpd-php5 .html .php .htm

Thoughts? Please be gentle. I haven't found any similar articles, and reading on PHP hasn't yet covered how to integrate the two how I need.

4
  • 1
    You have TONS of articles about that. `<div><?php echo "PHP here!";?></div> Commented Jul 1, 2013 at 3:49
  • 1
    How are you currently attempting this in your index.php ? Commented Jul 1, 2013 at 3:51
  • Just so you know, your About section isn't being shown properly. The anchor and/or content seems misplaced. Chrome 27 OSX Commented Jul 1, 2013 at 4:05
  • Jeemusu - <div id="content"> <div class="grid_4"> <div class="h1_viva">News from Facebook</div> <?php require('custom-facebook-feed.php'); ?> <p> Commented Jul 1, 2013 at 4:21

3 Answers 3

2

PHP is a server-side language. This means that all of it happens on the server, and then it outputs the html/javascript/css that the browser then receives, interprets, and displays.

Very simply, as long as your file is called "index.php" (which it seems to be), you can embed your php feed code in-between tags

Eg:

<body>
<div class="facebookContainer">

<?php
  //php code is here
  echo $facebookFeed;
?>

</div>
Sign up to request clarification or add additional context in comments.

2 Comments

This will produce a syntax error. Also, if you are only outputting one variable you should use the shorthand like this: <?= $facebookFeed; ?>
Fixed the missing semi colon - thanks. There are a few reasons I didn't use the shorthand - 1) he stated he was a beginner, and that syntax can be very confusing. 2) based on what he said, I don't think it is going to be outputting just one variable, and merely put that there to demonstrate that that's where the code went.
0

Another option, in case I misunderstood your constraints/goals, would be to pull in the facebook feed using JQuery. The downside to this would be requiring javascript for the page to load the facebook feed, but the plus side is that you would get a speed boost - if you load in the feed directly with php, you are going to be waiting for facebook to reply to your request before you can finish sending the page to the user.

It would be as simple as putting this script at the bottom of your page, before the closing body tag:

<script>
       $(document).ready(function() {

           $('div#facebookContainer').load('http://www.mac-works.com/dev/MG/mark3/custom-facebook-feed.php');

    });
</script>

5 Comments

You say at the bottom of the page - but how would that populate the section I want under //News from facebook. I'd assume I'd need to call the script in that section instead? or both?
The script goes at the bottom of the page, but the content will be placed in the facebookContainer <div>, which can be anywhere.
holy crap - this worked. I obviously have to fix the formatting, but it shows - The problem is it pushed the //Tour div below the facebook content. I missed something. I wanted it to appear next to it.
I fixed the formatting - however the content only loads in Chrome and FireFox. Safari error console displays: XMLHttpRequest cannot load mac-works.com/dev/MG/mark3/custom-facebook-feed.php. Origin mac-works.com is not allowed by Access-Control-Allow-Origin. I have seen a number of articles to allow cross site using JSONP, but being a n00b, I have no idea how to implement that. Any help?
Try using a relative path - since custom-facebook-feed.php is in the same directory, just do $('div#facebookContainer').load('custom-facebook-feed.php');
0

Create an iframe in the position you want to display your output. Use the url of the PHP script you currently have as the src attribute.

<iframe width="300" height="400" src="http://www.mac-works.com/dev/MG/mark3/custom-facebook-feed.php" seamless>

Style both to taste.

2 Comments

Ugh - iframe? is that my only option? this is a responsive page, which is why i was so proud - although some of the comments here are starting to wear at that...
No, it's not your only option. It's an option. The other answers here have different suggestions, but they require coding in PHP or Javascript, or both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.