Thinking About Running a Business Online? Join Internet Business Mastermind, FREE!
 


Connect Your Websites with PHP Widgets

In this lesson, you will learn how to create your first PHP widget. PHP widgets work very much like JavaScript widgets from visitor's perspective. Your website visitors will not be able to tell the difference between a JavaScript widget and a PHP widget both performing the same actions. In this lesson, we will use the Guest Blogger's Badge as an example.

Step 1: Get your HTML code ready

In this case, the HTML code for the Guest Blogger's widget is:

<a href="http://www.blogging-career.com"  title="Blogging as a Career"><img src="http://www.blogging-career.com/bc-guestbloggerbadge.gif" border="0"</a>


Step 2: Modify your HTML code and replace all the " with " to make it PHP compatible

Original Code:

<a href="http://www.blogging-career.com" title="Blogging as a Career"><img src="http://www.blogging-career.com/bc-guestbloggerbadge.gif" border="0"</a>


PHP Ready Code:

<a href="http://www.blogging-career.com"  title="Blogging as a Career"><img src="http://www.blogging-career.com/bc-guestbloggerbadge.gif"  border="0"</a>


Step 3: Open a new text file and copy &amp.amp.amp. paste the following code into it

<?php

$WidgetName = "WidgetCode";

echo "document.write('$WidgetName')";

?>

WidgetName is just a variable which can really be renamed into anything. Let's make it "badge" for our example.

WidgetCode is where you will replace it with your PHP ready code.

Step 4: Modify the neccessary codes and save the widget PHP file

Finalized PHP file looks like this:

<?php

$badge = "<a href="http://www.blogging-career.com"  title="Blogging as a Career"><img src="http://www.blogging-career.com/bc-guestbloggerbadge.gif" border="0"</a>";

echo "document.write('$badge')";

?>

We will save the text file as "bc-guestbloggerbadge.php"

Step 5: Upload the widget PHP file to your website

Step 6: Copy and Paste your widget fetch code to your websites

Your widget fetch code looks very similar to the fetch code of a JavaScript widget. In our example, it will look like this:

<script type="text/javascript" src="http://www.blogging-career.com/bc-guestbloggerbadge.php"></script>


You're done! When you make an update to your widget PHP file, all your niche websites will see the changes as long as they all use the same widget fetch code.