It's easy to setup your own toll free number for as little as $2/ month. Try Kall8 today and get your 800 number. Features include call forwarding, voice mail and fax, caller ID, email notifications, VoIP, and more.
Constant Contact has been in business since 1996 is one of the most reliable and trusted email marketing services around. Click here to activate your free 60 day trial courtesy of CWD Community.
I installed the views module popular content blocks (the all-time popular content block, and the recent popular content block), but noticed that they also listed the front page as the most popular, something that I felt was unecessary. This article discusses code snippets that will let you exclude certain node ID's (and paths) from inclusion.
In case you are wondering why you don't see the "popular content" views in your views settings, you need to do the following to get them to show:
You can adjust how many content items show by editing the popular content view under admin -> views. However, short of hacking the statistics module, I did not find a way to modify the view to exclude certain nodes. In lieu of this here is a PHP snippet that you can copy and paste into a new block that will let you exclude particular node ID's:
<?php
$result = db_query_range("SELECT n.title, n.nid, nc.nid, nc.daycount
FROM node n, node_counter nc
WHERE n.status = 1 and n.nid = nc.nid and n.nid != 3
ORDER BY nc.daycount
DESC ", 0, 5);
while ($node = db_fetch_object($result)) {
$output[] = l($node->title, "node/$node->nid") . " ($node->daycount)";
}
print theme('item_list', $output);
print '<p style="text-align: right; padding-right: 1em"><a href="/popular/latest">[ View All ]</a></p>';
?>
The node_counter table keeps track of page accesses; both daily accesses (in daycount) and alltime accesses (in alltime). The above snippet references daycount to produce a block of "today's popular content," while the snippet below references alltime to produce a block of "all-time popular content." I also specify nodes that I don't want included in the WHERE clause. In this case, my front page node ID is 3, so I exclude it with the line
WHERE ... and n.nid != 3
You could also cross-reference the url alias table to exclude nodes by path name.
<?php
$result = db_query_range("SELECT n.title, n.nid, nc.nid, nc.totalcount
FROM node n, node_counter nc
WHERE n.status = 1 and n.nid = nc.nid and n.nid != 3
ORDER BY nc.totalcount
DESC ", 0, 5);
while ($node = db_fetch_object($result)) {
$output[] = l($node->title, "node/$node->nid") . " ($node->totalcount)";
}
print theme('item_list', $output);
print '<p style="text-align: right; padding-right: 1em"><a href="/popular/alltime">[ View All ]</a></p>';
?>
I hope this proves useful to someone. Please post any questions/ comments below.
References: There is a further discussion of popular content blocks in this Drupal thread and a visual popular content block, similar to the one used on c|Net, discussed in this thread.
All Content © 2005 - 2010 Contract Web Development, Inc. All Rights Reserved. Privacy Policy | Terms of Use | Powered by Drupal
Not seeing the full code
Hello, thanks for writing this article! It's exactly what I'm wanting to do.
However, I don't see the code that you used to exclude a node from "Today's Popular Content" on the current page.
It jumps from "...here is a PHP snippet that you can copy and paste into a new block that will let you exclude particular node ID's:" to a block example - "Today's Popular Content".
I just have one node to exclude, so I'd really appreciate it if you could (re?)post the code in a comment.
Thanks,
Jim
Code view restored
Hi Jim,
Thanks for pointing that out! Since we wrote this article we've implemented new code filters, and it looks like they killed the code in this article. I've restored it - you should be good to go.
Popular content block with Drupal 6.6?
Thank you for this. I'm using Drupal 6.6 will this still work? I tried it but all I got displayed was the PHP code in plain text after i pasted it in the body. I'm doing something wrong aren't I?
Use input format to enable php code
You probably need to adjust your input format. Below the body, you should see an "input format" selection. Select "PHP Code" from the options.
If you don't see "input format," you may need to adjust your access control permissions via User Management -> Access Control.
If you don't see "PHP Code," you may need to adjust your filter settings for your user role.
Yo
Is it posible to exclude more nodes? With this I can exclude just one node or more?
Excluding nodes
You can exclude as many as you need to:
WHERE n.status = 1 ... and n.nid != 3 and n.nid != 4, etc.
Thank you!
Thank you very much!!!
very useful!
Very useful! I was looking to do exactly this -- you've saved me a lot of time! many thanks!
Very cool - it's always nice
Very cool - it's always nice to hear that my articles are useful to someone! Thanks for the mention!