PHP includes for Blogger
Before writing this post, I looked online to see if others have written about this same topic. This might as well be Michael Gray’s “Integrating Blogger Into Your Website: Part II”, which he never wrote — though he did write Part I.
Step 1: Switch Blogger files to PHP
First, you need to update your publishing settings so that Blogger publishes your posts in PHP, not HTML (thanks to DevDoctor):
- Set up your blog to publish via FTP (on Publishing tab)
- Change the ‘Blog Filename’ to index.php
- Change ‘Archive Filename’ to archive.php (on Archiving tab)
- Finally, delete the old index.html file from the blog directory (otherwise it will probably take precedence over the new index.php)
Once you’ve got Blogger pushing out PHP, you’re able to do PHP stuff with the site:
- Update the entire site at once – When I create a website, I always want to create the structure using PHP includes, so that I can set global site variables, and if I change it in one place, it changes across the whole website.
- Set active navigation – Using SSI includes, I used to have to include a different file for each blog section on the site so that I could up. Here, I just send a variable to the navigation.php file, which tells it what page is active.
Next, I will show how to include these files.
Step 2: Get the absolute path to the includes
Note: the most important part of this code is that it uses an absolute path, not a relative path.
To find the absolute path of the file you are trying to include, you can:
- Run the code below, and the error should show you the path in the error text itself, or;
- Can add this to a file in the same directory as the files you’re trying to include, then go to the file in your browser:
<?php echo realpath(dirname(__FILE__)); ?>
Step 3: Update your Blogger.com template
Once you have the absolute path for the file, you can add the includes to your Blogger template:
<?php
global $pageID;
$pageID = 1; // You can tell these files what page you're on
include('/absolute/path/to/website/includes/navigation.php');
include('/absolute/path/to/website/includes/header.php');
include('/absolute/path/to/website/includes/sidebar.php');
?>
Note: One of the items I was going to write about was passing some variables back and forth, but I’ve included only the $pageID variable. If you want to see more code, let me know in the comments below.
I’ve used this method in a couple of websites (designed by Atomic Idea and developed by Katz Web Design). Check them out to see the integrated Blogger blog:
- Amp Alarms
- Split Rail Fence Company
21 replies on “Integrate Blogger Into your PHP Website using Includes”
Hi,
Thanks for posting the 2nd half of the equation. I have what might be a silly question but still……can you tell me if after I bring my blogger blog under my own host if I will still be able to get to my blogger dashboard? Would I work on it in blogger as usual or would the dashboard somehow integrate into my site as well? This idea is new to me so I want to visit all the angles. Thanks.
Keep the good posts comming:)
Zack,
With this method, are you able to do comments etc on your own site or do you have to go into the blogger site to leave comments?
I am deciding which blog to integrate into my site. I got wordpress basic integration, but as soon as you clikc on comments it goes to the WP site. I want everything in my site.
Thanks,
Dave, comments are able to be left on the site itself, if you use Blogger Draft. Check out this Amp Alarms post as an example.
Hi,
I’m Looking to include blogger into my own site template but don’t know where to put the includes. I don’t understand how you should put an include to your own page in your own index php. I am looking for the php include code to include blogger, not my own page.. Sorry if this sounds verry dumb. Just don’t understand it.
Thanks for any help.
I’m reading this and it’s great stuff! My question is that, once your Blogger site is in PHP…this should enable a PHP redirect with, say, and affiliate link? Searching for a great way to cloak affiliate links in Blogger and this seems to be the BEST ONE if it’s possible?
I’m wondering what the procedure is if you are using a custom domain name? Blogger is discontinuing ftp support this month…
Update: We will no longer support FTP publishing in Blogger after May 1, 2010. Learn more on our dedicated FTP blog.
Bummer. 🙁
Hi Zack,
Glad you found my Blogger/PHP tips helpful. I recently completed a Blogger to Moveable Type migration – see http://www.devdoctor.com/blog/2010/02/blogger-to-remove-publish-via-ftp.php
The solution I found was Movable Type in static publishing mode. I’ll write up the details on my blog when I get chance, but basically, use Linux symlinks to “alias” the mt and mt-static directories so you can run multiple sites from a single code base/install, and create a new theme for each site you run. The in-built editor is not very good, so I’m looking to replace this with CKEditor or similar.
Good info. Helped me a lot.
I like thisd good services. I like you’re good feed back. Thanks share this good post.
SEO
The
Company’s share capital is expressed most of the times in Euro and is divided
into shares of any value, again expressed in Euro. The Company’s share
capital may also be expressed in another currency.
Hi. As I understand blogger supports php scripts? Can I integrate script like php forms to my blog? Will blogger support such script?
I am not sure. You can certainly try!
fantastic idea.
i like this post. will modify my blogger site..Logizire. this will be a great help.. awesome article.
when i check in internet.expo, its not working. what’s the plugin i need to use in inside the coding?
http://raovishal.blogspot.com/2011/11/php-session-and-cookies.html
lately, I did not give plenty of thought to giving responses on site page reports and have positioned responses even less. Reading through your pleasant content, will assist me to do so sometimes.
Dynamics training
These are actually great idea to use PHP language in blogger. I will surely try them and love to get the experience of PHP in my blog.