Excluding WordPress Categories from Kontera ContentLinks
4 May 2007Recently I was accepted into the Kontera program that places ContentLinks based on relevant keywords found throughout your site.
Kontera provides the following span tag to exclude the ContentLinks from passages of text:
<span name=”KonaFilter”></span>
This is really handy if you simply have a static area of text you want to exclude, however, it poses a program for dynamic content. My goal was to have the ability to exclude the Kontera ContentLinks based on a WordPress category. I could manually enter this code into every post, but that would be quite a hassle, and also it wouldn’t take into account all the previous entries in that category.
Here is how you can modify WordPress to exclude Kontera based on categories:
1. Find the category you want to exclude. Each category is represented by an ID number. In my case I was looking to exclude my Advertising category, because I cannot mix Kontera with some of the other advertising posts that I do. Based on my scenario, I want 5.

2. WordPress uses loops in various PHP files to display the posts. The three most common places for this file will be index.php file, single.php, and page.php. These three files will be located under your wp-content\themes\theme_name\ directory.
3. Here comes the code. Each loop has something or something very similar to post your content:
<?php the_content(’Read the rest of this entry »’); ?>
Our goal is to create an if/then statement using a built in WordPress function to either wrap the content with the <span name=”KonaFilter”></span> or not, based on the category.
I’ll be using the in_category() function.
Here is the code I wrote for mine:
<?php if ( in_category(’5′) ) { ?>
<div class=”entry”>
<?php echo “<span name=\”KonaFilter\”>” ?>
<?php the_content(’Read the rest of this entry »’); ?>
<?php echo”</span>” ?>
</div>
<?php } else { ?>
<div class=”entry”>
<?php the_content(’Read the rest of this entry »’); ?>
</div>
<?php } ?>
This will probably vary slightly from theme to theme, but will be very close to what you need to do. You can also exclude multiple categories, and you’d list them all with in_category().
I hope this helps others that may be trying to achieve the same scenario. I couldn’t find any documentation on this so I decided to write this post and make it available for others to use.
Cheers!
Update:
Here is my new and improved way of doing this using the same technique. While the method above works fine, it presents two problems.
1. It may still may put ConentLinks on other text in your pages where you don’t want it. Then you’d have to painfully go and wrap the code with the KonaFilter.
2. Using the KonaFilter code is not XHTML 1.1 complaint code, which will present a problem if you want to pass W3C Validation, which has been important to me lately.
The better way to achieve this is using the following code:
<div class="KonaBody"></div>
The great thing about using this class is that Kontera automatically detects you’re using this, and only places ContentLinks inside code you wrap within it.
By doing this, you then code your in_category function to say, if code isn’t in this category, then place ContentLinks around it. Here is the code I used for mine:
<?php if (! in_category(’5′) ) { ?>
<div class=”entry”>
<?php echo “<div class=\”KonaBody\”>” ?>
<?php the_content(’Read the rest of this entry »’); ?>
<?php echo”</div>” ?>
</div>
<?php } else { ?>
<div class=”entry”>
<?php the_content(’Read the rest of this entry »’); ?>
</div>
<?php } ?>
Much better! Hope this update helps!
|
|
4 Responses to “Excluding WordPress Categories from Kontera ContentLinks”
Leave a Reply
Thanks For Visiting!
May 20th, 2007 at 10:34 pm
[…] Check it here. […]
October 17th, 2007 at 9:15 pm
Good information you have here. But what should I do if I just want to avoid the ads from appearing on my blog header (title and description)? Thanks.
November 25th, 2007 at 6:49 am
I operate niche market websites. I have been approached by manufacturers in my field of expertise to advertise on my websites.
I like the appearance of contentlinks when the cursor scrolls over the keyword. There is an information window that appears before one clicks.
Is the information window an exclusive product of Kontera? I would like to use just the information window and link to my own advertiser’s designated webpages.
If the window feature is not exclusively Kontera’s could you tell me where to go to find the code, etc.
Thank you.
November 25th, 2007 at 10:04 am
It’s part of Kontera’s system, but it can easily be done with some javascript.