Categories
Blogging Tutorial

Integrate Blogger Into your PHP Website using Includes

Blogger Banner

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):

  1. Set up your blog to publish via FTP (on Publishing tab)
  2. Change the ‘Blog Filename’ to index.php
  3. Change ‘Archive Filename’ to archive.php (on Archiving tab)
  4. 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:

  1. Run the code below, and the error should show you the path in the error text itself, or;
  2. 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

Step 4: Ask any questions you might have below

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

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.

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,

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?

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.

when i check in internet.expo, its not working. what’s the plugin i need to use in inside the coding?

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

Comments are closed.