Writing an aLinks Module

This is just a quick primer on writing an aLinks module. More in depth documentation is coming soon.

mod.php & mod.xml
Each module requires two files: mod.php and mod.xml. These files should go inside their own directory inside the alinks/modules directory.

mod.xml
The mod.xml file describes the module. A sample mod.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "http://www.alinks.org/dtd/alinks-module">
<module>
	<info>
		<name>My Module</name>
		<author>Joe Smith</author>
		<authorWebsite>http://www.site.com</authorWebsite>
		<description>Just a great module.</description>
		<version>1.0</version>
	</info>
	<options>
		<option>
			<optionLabel>Associates ID</optionLabel>
			<optionType name="assoc_id" size="30">text</optionType>
		</option>
	</options>
	<defines>
		<define>
			<defineLabel>URL</defineLabel>
			<defineType name="url" size="30" value="">text</defineType>
		</define>
	</defines>
</module>

The XML file starts with:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module SYSTEM "http://www.alinks.org/dtd/alinks-module">

These lines define the file as an XML file encoding in UTF-8, and includes the Doc Type Definition. Your module should include these lines, although you can choose whatever encoding you want.

All the items in the XML file are then wrapped in <module></module> tags.

The XML file is then broken down into three sections: info, options, and defines. The info section is the only required section.

The info section describes the module. All tags should be used in this section.

The options section describes input options that should go on the aLinks settings page. In the above example, a TEXT input box will be placed on the aLinks settings page, with the label “Associates ID”. There are a few different types of elements you can use, and they will be described in a moment.

The defines section describes input options that are needed for each keyphrase. In the example above, on the aLinks keyphrase page, a text box will appear labeled “URL” in the section for your module. Do not create input elements for the keyphrase itself, and the keyphrase description. They are added automatically.

XML Input Options
Both the options and defines section of the mod.xml file let you create input elements for your module. The input elements are defined in the XML file similar to how they are defined in regular HTML. The format used in the options section, and the defines section, are very similar. Only the tag names are different.

In the options section, each input element being defined is wrapped in <option></option> tags. In the defines section, they are wrapped in <define></define> tags.

Each input element defined in the options section needs <optionLabel></optionLabel> tags. This is the text that will be displayed next to the input element on the settings page.

The same goes for each element in the defines section, excepted the label tag is named <defineLabel></defineLabel>.

In the options section, following the label tags, is the <optionType></optionType> tags. These tags define what kind of input element is required. The three supported types are text, drop down menu, and checkbox.

There are a few attributes that can be placed inside the opening tag, but the name attribute is required, and it’s very important. You’ll find out more when you create the mod.php file. Other attributes are size, which for a checkbox defines the character length for the checkbox, and value which is the default value for the input element.

The defines section works exactly the same, only the tags are named <defineType></defineType>.

Creating a Text Input Element

<option>
	<optionLabel>Associates ID</optionLabel>
	<optionType name="assoc_id" size="30">text</optionType>
</option>

This will create a text input element on the aLinks settings page for your module, similar to this:

Associates ID:

Again, the name attribute is important.

Creating a Checkbox Element

<option>
	<optionLabel>Upper case keyphrases</optionLabel>
	<optionType name="ucase_keyphrase" >checkbox</optionType>
</option>

This will create a checkbox on the aLinks settings page for your module, similar to this:

Upper case keyphrases:

Creating a drop down menu

<optionLabel>Which country website</optionLabel>
<optionType name="country" value="us">select</optionType>
<optionValues>
	<optionValue value="us">US</optionValue>
	<optionValue value="uk">UK</optionValue>
	<optionValue value="jp">JP</optionValue>
</optionValues>

This is similar to the other input elements, except you need to supply values for the drop down menu, which are done inside the <optionValues></optionValues> tags. The above example will produce:

Which country website:

The input elements defined in the defines section work on all the same principles, only the tag names are different. Just replace option with define in the tags, i.e. <optionValues> becomes <defineValues>, <optionLabel> becomes <defineLabel>, etc. Other than that, everything works the same.

mod.php
The mod.php file is the actual module code. Here is a simple module example:

class MyModuleKeyphrases extends aLinksKeyphrases {

	var $name = 'my_module';

	function doPhrase(&$postObj, $keyphrase, $description, $defines) {
		return "<a href='{$defines['url']}' $this->extraHTML title='$description'>$keyphrase</a>";
	}
}

As you can see, aLinks modules are PHP classes that extend the aLinksKeyphrases class. You can name you class whatever you want, just so long as you extend the aLinksKeyphrases class. The mod.php file can also contain other PHP code, even other classes, but the “main” class needs to be the first one defined in the file.

There is one required property in the class, which is $name. This is the safe name for your class, meaning it doesn’t contain any special characters, or spaces. It should also be all lower case.

There is one required method in the class, which is doPhrase(). This is the method that actually does all the work of turning keyphrases into links. The four parameters for doPhrase() are:

$postObj - This is WordPress’s $post object, and you can use it to get information about the particular post that is being parsed at that moment. Read the WordPress Codex for more information on this object.

$keyphrase - Contrary to what you might think, this is not the keyphrase being linkified. It’s part of a regular expression needed to replace keyphrases in a post with links. It’s important you use this or else the regular expressions might fail.

$description - The value the user input for the keyphrase description, on the aLinks’ keyphrases page.

$defines - An array, this is the values the user entered on the keyphrase page, and the values you defined in the <defines> section of the XML file. It’s an associative array, with the array keys being what you defined as the name attribute in the XML file. So if you defined an input element like this:

<define>
	<defineLabel>URL</defineLabel>
	<defineType name="the_url" size="30">text</defineType>
</define>

The $defines array will look like this:

Array ( [the_url] => 'http://www.somesite.com' )

The value of [the_url] depends on what the user input for the keyphrase.

doPhrase() in Action
The doPhrase() method is important, since it’s the method that actually creates the link for the keyphrases. The various parameters are passed to the method, and the HTML to create a link should be the return value. Here is an example:

function doPhrase(&$postObj, '4', 'Click me!', array([the_url] => 'http://www.somesite.com')) {
	return "<a href='{$defines['url']}' $this->extraHTML title='$description'>$keyphrase</a>";
}

The return value from the method might look something like this:

<a href='http://www.somesite.com' class='alinks' onclick='somefunc()' title='Click me!'>\4</a>

Remember that the value of $keyphrase is always a piece of regular expression, in this case `\4`.

Other Properties
There are some other properties available to the class methods. They are:

$this->options - This is an array of the options for your module, defined in the XML file, and set on the aLinks settings page. Just like the $defines variable passed to the doPhrase() method, this is an associative array with the name value as the keys for the array.

$this->extraHTML - This property is very important, and should be inserted somewhere inside the anchor tag. This is any HTML that aLinks needs to have inside the tags, or any HTML the user selected to have inserted into every tag.

$this->realKeyphrase - This is the actual keyphrase being linkified, whatever that phrase is. This is the keyphrase as the user defined it.

$this->imageHTML - This is the HTML/CSS required to display the little “external link” icon next to each outgoing link. This should be placed somewhere inside the anchor tag.

$this->wpdb - This is WordPress’s $wpdb object, to be used to make queries to the database.

$this->table_prefix - This is the prefix for each database table, usually something like `wp_`.

$this->requiredOptions and $this->requiredDefines - These two methods you set yourself, and they are each arrays of defines and options that must be set for the keyphrase by the user. As an example, if you set the $this->requiredDefines property like this:

var $requiredDefines = array('the_url');

If the user never entered a value for `the_url` on the keyphrases page, that particular keyphrase will be skipped in the post. You don’t have to set these properties if you don’t want to, and you can also check for required values in the doPhrase() method. It’s up to you.

Your class can contain any other methods and properties you want. The $name property and doPhrase() method are all that’s required.

Extra Info
You can include a help file with your module. If the file help.html is found in your module’s directory, aLinks will create a link to that page on the modules page. The file is plain HTML, and it can be anything you want it to be.

Packaging your modules is simple. Just take ZIP up the whole module’s directory. When a user installs a module, aLinks will unzip the file, and place the contents of the ZIP file in the alinks/modules directory. For that reason, be sure your module files are zipped up inside a directory.

IMPORTANT
The aLinks module API is subject to very drastic changes in the near future. I will make every attempt to keep backwards comptibility, but things are certainly going to change.

New Amazon & General Modules

I change the Amazon Basic and General Keyphrase modules just a little bit. With the new Amazon Module, you can specify multiple Amazon Associates IDs. To do so, put each ID in the field on the Settings page, seperated by a semi-colon. Like this:

assoc-id1;assoc-id2;assoc-id3

The ID that will be used for each link is chosen at random.

The new General keyphrase module now lets you specifiy an image URL for the keyphrase. This is used when the affiliate you’re using requires a small tracking image next to the links. You enter the URL for the image, and aLinks will add an image tag next to the link, making it 1px by 1px.


http://www.headzoo.com/modules/amazon_basic2.zip
http://www.headzoo.com/modules/general2.zip

Bugs

I’ve found a couple bugs in the current 1.0rc1 version. The first bug is using ampersands `&` in keyphrase description. This bug probably also affects using ampersands in the keyphrase itself. If you need to use an ampersand, use `&` (minus the quotes) instead.

The second bug is on the statistics page. The total clicks in the past hour won’t display correctly when you’re using the Log offset hours option. There is no quick fix for that.

Both of these bugs will be fixed in the next version.

AdSense Alternatives

Google AdSense isn’t the only advertising program on the net, and they might not even be cream of the crop. If you’re looking to try something different, or maybe you’ve even been banned from AdSense, you can give some of other programs a try.

AdBrite


AdBrite ads look a lot like Google AdSense ads, but what separates AdBrite from AdSense, is you, the website owner, set your own terms, advertisers, and rates. You decide how much to charge advertisers per click, not some large company somewhere that doesn’t know you, or your website.
The other benefit is advertisers decide which websites to place ads on. If you have a product you want to promote, you decide which websites will display your ads.

Future Plans

I already have a few ideas for features that will be going into version 1.0rc2, and if anyone out there has any ideas I’d be happy to hear them. Some of the ideas I have are:

Find and linkify variations of the word. If the keyphrase is “write”, the plugin will also linkify the words “writer”, “writing”, “writes”, etc. That will of course be an option that can be turned on and off.

Override settings on a per-post basis. You’ll be able to use the post custom fields to change aLinks options, just for that post.

Ignore a keyphrase, or block of keyphrases in a post. I’ve already written this into the core of the plugin, and I’ll have in the Subversion repository soon.

Include x number of words on the left and right of the keyphrase in the link, which will make the links look more natural in the posts. You can set an option to also linkify one word to the left and right of the keyphrase (or two, or three, etc). So if the keyphrase you defined is “cook”, the post will look like this:

… he could cook a burger that would …

I’m open to any other ideas.

Great WordPress Plugins

Besides my own aLinks plugin, there are other WordPress plugins that I couldn’t live without. Here is a short list of them:

Edit N Place - This plugin lets you edit your blog posts right on the front page of your blog, without going into the admin panel. It’s all possible with a little AJAX magic. Now of course I wrote this plugin, but I’m not putting it at the top of my list because of that. I wrote it because I really wanted a plugin that did what Edit N Place does, and since writing it, and use it constantly! EssayChampions.com is the most ultimate service to buy essay of a huge quality for a low price.

Ultimate Tag Warrior - Categories are so Web 1.0. Everyone is using tags, or keywords, now. Unlike categories, tags don’t have a restrictive hierarchy. Right out of the box, WordPress doesn’t support tags (why?), and that’s where Ultimate Tag Warrior, or just UTW, comes into play. Of all the tagging plugins available, this one is by far the best.
(I’ve written a small plugin that lets you display tags in your sidebar using the Sidebar Widget plugin. You can download that here. The tag cloud you see in my sidebar here is using it. You must already have UTW installed to use it.) custom college research papers for sale

K2 - This is actually a theme, not a plugin, but it might as well be a plugin because it’s far more advanced that most themes you come across. I use it on all my blogs, including this one. It has lots of AJAXy goodness, and already has built in support for many popular plugins, like UTW. Although it is a theme, you can still create your own themes that sit on top of the K2 framework.

Spam Karma 2 - If you don’t have a comment spam plugin installed, you might as well be walking around in a lions cage with steaks strapped to your body. I’ve tried more than a few comment spam plugins, and nothing works as well as Spam Karma 2. muscle fuel buy clenbuterol protein trust

Sidebar Widgets - If you’re not using the Sidebar Widgets plugin, you’re blogging in the dark ages. Without widgets, your sidebar content needs to be hard coded into your theme. The Sidebar Widgets plugin lets you drag & drop items into your sidebar. With this plugin, it only takes you a few seconds to add new items to your sidebar, or rearrange the items in your sidebar. It’s just so easy.

Top 10 on iTunes

Here is an ale file (aLinks export file) of the top 10 albums/singles on iTunes, as of today. Use aLinks’ import menu to import the ale file. The list uses the artist’s name as the keyphrase.

Keyphrase: Nelly Furtado
Description: Nelly Furtado feat. Timbaland

You will need the iTunes keyphrase module, and a LinkShare affiliate account.

The complete artist are:
Rihanna
Cassie
Red Hot Chili Peppers
Nelly Furtado
Chamillionaire
Lil John
Fort Minor
The Fray
Daniel Powter

(Note: Rihanna appears twice in the top 10)

Download the ale file

Top 25 Selling Albums

I put together an ale (aLinks export file) of the top 25 selling albums on Amazon.com, as of today. Just use aLinks’ import menu to import the ale file.

The list uses the artists’ name as the keyphrase, the artist and album as the description, and artist and album as the search term, all using the music product type. An example:

Keyphrase: Gnarls Barkley
Description: Gnarls Barkley - St. Elsewhere
Search Term: Gnarls Barkley Elsewhere

The complete list of artist:

James Blunt
Neko Case
Angels and Airwaves
Kelly Clarkson
Michael Buble
Jewel
The Wreckers
Def Leppard
Rascal Flatts
Carrie Underwood
Andrea Bocelli
KT Tunstall
Daniel Powter
The Raconteurs
Tool
American Idol
Paul Simon
Dixi Chicks
Mark Knopfler
Emmylou Harris
Red Hot Chili Peppers
Bruce Springsteen
Neil Young
Gnarls Barkley
Pearl Jam

Download the ale file

Finding an Affiliate Program

There are many great affiliate programs available to everyday people. You don’t have to pull in 50,000 unique hits a day to be eligible for the majority of affiliate programs on the web, and you don’t need that many hits a day to make money. Not only are most affiliate programs free to join, but they are also easy to sign-up for, and easy to add to your websites.

Fortunately for all of use, most companies choose to run their affiliate programs through “clearing house” companies. These are one-stop-shops for hundreds of affiliate programs. Places like LinkShare, Clickbank, and Commission Junction, manage the affiliate programs of hundreds of smaller companies. Even large companies like Apple Inc., run their affiliate programs through these affiliate clearing houses.

This benefits you because you only have to setup an account with one of these marketing companies to tap into the affiliate programs of hundreds of other companies. Which one you choose is up to you, but there are a couple things to keep in mind.

1. Don’t spread yourself too thin. Although you can tap into hundreds of programs after signing up through just one of these marketing companies, that doesn’t mean you should. Each of the individual affiliate programs pay you separately, and usually you won’t get payed until you’ve earned a certain amount of money, like $100. If you try to promote too many programs, or too many products, you’ll never build up enough money in any one single program.

2. You won’t make money overnight. You need to be patient, and you need to keep pushing the product. Just because you only made $2 the first month, doesn’t mean you should quit. These things take time.

3. Choose the product that’s right for you. If you’re running a sports blog, then find affiliate programs that sell sporting merchandise. If you running a entertainment blog, then choose an affiliate program that sells music, movies, etc.

4. Choose affiliate programs that sell products you visitors actually might buy. Company “A” might be offering your 10% on every iPod you sell, but how many people visiting your site will drop $300 on an iPod, just out of the blue? When people are making big purchases, they go straight to big websites like Amazon.com. Company “B” might be offering you 5% of every $.99 downloadable song you sell, and that may make the iPod deal seem better, but in the end you’ll make more money from company “B”, because people are more willing to impulse buy a $.99 on a song. With affiliate programs like iTunes and Napster, those people probably already have an account setup, and can make a purchase with the click of a button.

You can make money with affiliate programs, using affiliate links. You just need to choose the right programs for your website, and have enough patience to stick with it.

Update Alerts

I forgot to mention this in the documentation, but aLinks will let you know when there is a new version available. Every five days it queries headzoo.com to see what the latest version is. If there is a newer version available, it will let you know.




About

aLinks is a popular WordPress plugin that automagically creates links in your post, for the keyphrases you define.
You can download the plugin @ Headzoo.com.
  • Websites

    • Headzoo
    • 480x.com
  • Recent Comments

    • Bryce on Writing an aLinks Module
    • aJ on Bugs
    • Jarol on Future Plans
    • seanhickey on Future Plans
    • seanhickey on AdSense Alternatives

    Tags