Show Ads Based on Content Length
Filed in: Make Money Online, WordPress — February 17th, 2007
Problem: Currently I am displaying two blocks of ads on each blog post, one at the top of post, the other at the end of post.
The ad placement is ok but it becomes a problem when I have short posts, which looks like a full page of ads with hidden content. I want to selectively show second ad block only if content is more than 100 words.
By referring to a word count code on WordPress Support, I managed to hide second ad block if content is less than 100 words.
Here is the code. It is for WordPress only. Add the following code after "the_content" function in the "single.php" of your WordPress theme.
-
<?php
-
$countpost = $post->post_content;
-
if ($words> 100) {
-
?>
-
<!-- YOUR AD CODE HERE-->
-
<?php } ?>
My two cents
This is a simple WordPress hack. I hope you find it useful to have more flexible control on ad placements.
Popularity: 3% [?]
Comments Feed
TrackBack URL
February 18th, 2007 at 11:17 pm
emm.. thanks for the tips
February 19th, 2007 at 1:11 pm
[...] Usually, we place our ad blocks below or above the content. While this placement is OK for posts with good lengthy content, it would look ugly on posts with short content. LiewCF has come up with a solution to selectively show the second ad block only if the post’s length is above a certain threshold of word counts. [...]
February 20th, 2007 at 4:39 am
Very informative and practical blogging tricks.
Happy Chinese New Year LcF!
February 21st, 2007 at 5:05 pm
[...] Liew CF, salah satu “pro” blogger terkenal dari Malaysia, beberapa waktu lalu memposting tips untuk menampilkan iklan secara selektif, yaitu berdasarkan panjang dari content suatu halaman. Trik yg hanya bisa digunakan untuk platform Wordpress ini (sorry Blogspot ) menentukan layak tidaknya suatu iklan dimunculkan berdasarkan jumlah kata yg ada di halaman tersebut. Salah satu keuntungan dari penggunaan trik ini adalah kita tidak perlu menjejali halaman dengan iklan apabila kebetulan kita melakukan posting singkat. [...]
February 22nd, 2007 at 3:16 pm
[...] Referring from LiewCF Blog Show Ads Based on Content Length [...]
May 15th, 2007 at 7:22 pm
[...] Post üblicher Länge noch passt, sieht es bei kurzen Posts einfach schrecklich aus. LiewCF hat hierfür einen Hack veröffentlicht, der es ermöglicht, den zweiten Anzeigeblock [...]
May 24th, 2007 at 12:09 am
[...] few months ago, Liew CF – One of Malaysian pro-blogger write a post about trick for displaying advertisements depends on the length of content. Unfortunately, that trick only applied for Wordpress platform. That trick automatically [...]