1

I have added a "node title" field. I want to add this sort criteria to the node: the number of times the node has been viewed by visitors in a week, descending.
If I want to add a sort criteria with PHP code and a SQL query to insert in Views module, how should I do?

ps:i have overwritten a field. i want to query the database and using the query to Sort Criteria**how to add the custom one

  • You don't alter the code of Views to add a new sort criteria: you create a module that implements the new criteria. Are you sure there isn't already a similar sort criteria? – kiamlaluno May 18 '11 at 16:58
  • yeah.i am sure,if i create a module that implements the new criteria.how do i do? – enjoylife May 19 '11 at 0:30
3

First, make sure you have Drupal's Statistics module enabled and collecting page view statistics.

In Drupal 6, you need to enable Count content views under admin/reports/settings. This will count total node views and give you total day count. Unfortunately, it does not give you a weekly view count by default.

This will give you a sort criteria for Node statistics: Total views and Node statistics: Views today.

Upon closer inspection of the day count for node views, this value is reset to 0 every 24 hours by statistics_cron. This value would prove more useful as a sort criteria if it was the most recent 24 hour's node views. So, the Node statistics: Total views would be your best bet.

NOTE: See Statistics Granularity module for week, month and year.

| improve this answer | |
  • thank you..if i want to add a Sort criteria to views. do you know how to add it? – enjoylife May 19 '11 at 2:43
  • Yes. Edit the view. There's a section called "Sort Criteria". You will find the relevant sorting criteria under "Node statistics". You might also want to install the Advanced Help module to read Views documentation. – jwal May 19 '11 at 2:52
  • thank you, i know that. but i have overwrote a field. i want to query the database and using the query to Sort Criteria – enjoylife May 19 '11 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.