Linux.com

Feature: PHP

Quick custom text ad placement in WordPress blog categories

By Tina Gasperson on May 18, 2007 (8:00:00 AM)

Share    Print    Comments   

WordPress plugins abound for Google AdSense and other third-party text ad brokers, but what happens when someone wants to buy ad space directly from you, on a specific category page in your blog? You can easily add static HTML text ads to your category search result pages by creating category-specific page templates.

Because most WordPress themes have a single template for archives, aptly named archive.php, it's not immediately apparent how to place a text ad on a specific category results page. But never fear: by default, WordPress searches using what it calls a "template hierarchy." By taking advantage of the template hierarchy, it's easy to make a special page that keeps your text ad where it belongs.

The template hierarchy works like this: if your visitor clicks on category #3, WordPress first looks for the most specific template: category-3.php. If it doesn't find that, then it goes after the more generic category.php, and then archive.php, and if it doesn't find that, it finally drops back to index.php. Armed with this knowledge, you can create a category-specific template using archive.php as a base. (Note: your categories probably have actual names, not numbers, but WordPress assigns ID numbers to categories, just as it does with pages and posts. If you don't know the ID numbers off the top of your head, look in the administration panel under Manage -> Categories; the numbers are in that first column.)

To create your custom category page, open a copy of the archive.php file in a text editor and save it with a name that matches whatever category number you want to display the ad in -- category-#.php. Place the static text ad into your new category-specific PHP file by surrounding the HTML code with <div id="sticky-snip"></div>. Then paste that snippet, including the div tags, into the file, directly under this line of code: <?php get_header(); ?> , as in this example. Save the file, upload it to wp-content/themes/your_theme, and you're done.

Granted, this is static code in a dynamic page and therefore not the most elegant solution, but it works. You PHP wizards out there might have a better way to write this, especially for situations where you need to publish several different ads in different categories. In that case, we welcome your suggestions -- or a new plugin.

Tina Gasperson writes about business and technology from an open source perspective.

Share    Print    Comments   

Comments

on Quick custom text ad placement in WordPress blog categories

Note: Comments are owned by the poster. We are not responsible for their content.

Advertising

Posted by: Anonymous Coward on May 19, 2007 06:02 AM
Advertisements are the evil of the internets.

#

Re:Advertising

Posted by: Anonymous Coward on May 28, 2007 01:02 AM
That's true!
Adblocks rules!<nobr> <wbr></nobr>:-)

#

Quick custom text ad placement in WordPress blog categories

Posted by: Anonymous [ip: 58.182.161.6] on August 21, 2007 04:14 PM
There are plugins to manage direct selling. WP Text Ads is one such plugin. You can even sell ads for the whole blog, home page and per-post.

#

SPEND $55 PER MONTH EARN $1336 PER MONTH WITHOUT WORK

Posted by: Anonymous [ip: 61.17.52.137] on October 01, 2007 11:57 AM
http://www.myberrytree.com/bt86821


Description : 100% legal company New way to earn money without work.
Just participate in business with paying $55 per month
and earn $1336 every month. Just lauched join first to
get top position to earn early.

income proof on www.mycashcheck.com

#

Quick custom text ad placement in WordPress blog categories

Posted by: Anonymous [ip: 85.102.232.223] on October 02, 2007 04:24 PM
www.estetikforum.net

#

Very Helpful!

Posted by: Anonymous [ip: 70.16.61.212] on January 10, 2008 05:38 PM
This worked for my categories page! Thanks!

Do you know how to apply this same idea to archived pages-- pages organized by their dates?

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya