Modifying Your Theme
Now that you have defined your sponsor ad data, we'll modify the theme to use this information. In order to enable the placement of your ads, you need to insert a simple function call at the appropriate position within specific theme files where you want the ads presented. Refer to our layout sketch to track the changes we make to the theme files.
The syntax for the function call looks like this.
<?php
if (function_exists('cd_ad_zone')) {
cd_ad_zone(zone_id);
}
?>
Note: It is always a good idea to place any function call within a conditional statement to determine if the function is available. If the function is available, then it will be executed when WordPress processes this file. If it is not present, then it will simply be skipped without causing an error.
The function name is cd_ad_zone(zone_id). You replace zone_id with the numeric zone identifier you specified when you created the zone.
We'll start off with the header.php file. Open the header.php with a text editor. Since we want our header ad (zone 1) positioned next to the logo, we need to locate the code that refers to the header text. In a WordPress 2.x and earlier theme, this looks like the following.
<div id="header" role="banner">
<div id="headerimg">
<h1><a href="<?php echo get_option('home'); ?>/">
<?php bloginfo('name'); ?></a></h1>
<div class="description"><?php bloginfo('description'); ?></div>
</div>
</div>
Note: For WordPress 3.x and later, your header.php theme file will be different. You will need to modify the style definitions to place the header image as a background image so that your banner ad image will display as an overlay.
We need to place our function call inside the <div id="header"> tag just before its closing </div> tag. We place our function call there so that we won't interfere with the normal layout of the theme. The modified file now looks like this.
<div id="header" role="banner">
<div id="headerimg">
<h1><a href="<?php echo get_option('home'); ?>/">
<?php bloginfo('name'); ?></a></h1>
<div class="description"><?php bloginfo('description'); ?></div>
</div>
<?php
if (function_exists('cd_ad_zone')) {
cd_ad_zone( 1 );
}
?>
</div>
That's all that needs to be done to the header.php file, so save the changes and upload the file to your server. Access your blog URL to view the changes. If all went well with the definitions you should see PSACentral banner ad displayed in the header.
The next zone we need to define from our layout sketch is for zone 5, the sidebar zone defined for our Google ad. Open the sidebar.php file with a text editor. Take a moment to browse through the code so that you become familiar with the different elements and their positioning. what we need to look for is a location within the sidebar file to insert our function call.
Note: The cd-ad-sponsor plug-in is widget ready. You may add multiple widgets to your theme, each using the Zone IDs you defined. See Manage Zones for more information about defining zones for your ads.
As an example, let's say that the sidebar contains a listing of our blog categories, followed by a listing of archives, and finally a listing of links. Let's put our zone 5 function call between the archive and link listings, like so.
</div>
<?php
if (function_exists('cd_ad_zone')) {
cd_ad_zone( 5 );
}
?>
<div class="Block">
Save the changes and upload the sidebar file to your server. Access your blog URL to view the changes. If all went well with the definitions you should see the Google ad displayed in the sidebar between the archive and link listings.

Email