Yesterday, I explained how to keep Kontera ads out of your articles by manually adding tags everytime you write an article. Today, I’ll show you how to modify your template so you don’t need to remember to insert the pesky ads every time.
Here’s how to, in three ‘easy’ steps:
- Create a category for your sponsored articles. You can call it whatever you like. After you created it, go to the dashboard, and visit Manage=>Categories to determine the number of that category. (The category for my sponsored ads is 12.)
- Modify your main and archive templates as shown below. Tweaking will be required because templates vary.
- Once the template is modified, always place all your sponsored articles in the sponsored category.
How to modify your template
To set up your template, you need to use an “if/else” statements to wrap <span name=”KonaFilter”></span> around the content of sponsored posts; wrap <span name=”KonaBody”></span> around the content of other posts.
Here is a bit of example code showing where to place the ‘if/else’ statements relative to the cotent. In my example ’12′ is the category number for my sponsored posts; change that number to match the category for your sponsored ads.
— code starts here-
<?php
// The following if and else statements insert the first part of the span tags.
// These are the tags you want in the article.
if (in_category(12) ) {echo(‘<span name=”KonaFilter”>’);}
else {echo(‘<span name=”Konabody”>’); }
?>
<h2 class=”title”><a href=”<?php the_permalink() ?>”
rel=”bookmark” title=”Permanent Link: <?php the_title();
?>”><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<div class=”posted”><?php the_time(‘M d Y
h:i a’); ?> |
<?php the_category(‘ and ‘);?> |
<?php comments_popup_link(‘No Comments
»’, ’1 Comment »’, ‘% Comments »’);
?><?php edit_post_link(‘ | edit this’); ?>
</div>
<!- this closes the span tag->
</span>;
<!- this sets a NEW tag and keeps ads out of the comments. ->
<span name=”KonaFilter”>
<?php comments_template(); ?>
<?php echo(‘</span>’); ?>
--- code ends here--
This code should do the trick for you! Of course, tweaking may be required because the guts of your template will look different, but this should give you a head start.