Free Logo Creator

Logo creation is a long, drawn-out creative process that can cost millions. But a good logo doesn't have to cost a fortune, and you don't even need to hire a professional design team. Check out Logo Creator (Win | Mac) to get started, read our article on obtaining your own Free Logo Creator.

Restore Images on your Digital Camera Card

Uh oh - you just took a bucketful of honeymoon photos and towards the end of the trip your friend borrows the camera and accidentally formats the memory card.  Ahhhhh!!!  Don't freak out yet. Check out Disk Doctor and get $5 off as a CWD visitor. It just may save the day.



Nov 02 2006

Excluding Nodes from Drupal's Popular Content Blocks


Filed under: Content Management Systems » Drupal,
Tools:

Upgrading the Views Popular Content Blocks

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:

  • enable the statistics module
  • browse to admin -> settings -> statistics -> and enable "count content views."
  • go to administer -> blocks -> and enable the "popular content" blocks.

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:

Today's Popular Content


[ View All ]

Code Explained

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.

All-Time Popular Content


[ View All ]

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.

Average: 4 (11 votes)
Select your preferred way to display the comments and click "Save settings" to activate your changes.

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!

Smiling

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!!!

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.

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.