0

I am counting views per entry, and I have a 'Most Popular' section on the homepage that shows the most popular entries using

orderby="view_count_one"

I am finding this list tends to be the oldest entries, since they have been around so long they have the most views.

Is there away to either:

  • divide the views by number of days active and sort on that or
  • only show the last 30 days?

Any ideas?

Thx!

Added: I tried display_by="day" limit="30" but that lists all entries in 30 days and kills my entry limit breaking the page layout. I am currenty showing 7 entries, and 30 is too much.

For example, I would need somethind like display_by="day" day_limit="30" limit="7" (I know that wont work ;) just example)

I also tried to set the start by date range by using:

localize->format_date('%Y-%m-%d %H:%i', ee()->localize->now - 3600); ?>

from PHP conditional inside EE conditional - parse order problem

but that brakes my page and throws an error about line 45 referring to ()

  • Now I see what you mean. The problem is that the view_count_one will just increment, there is no way to find out what the count has shown 30 days before. The older entries with a lot of views will always be on top when ordering by view_count_one. There is an add-on from Solspace which lets you perform the desired action: "Tracker" (devot-ee-link: devot-ee.com/add-ons/tracker ) – BNetz Apr 27 '14 at 13:10
  • take a look at my edit to my answer. It's no solution but something you could quickly overread in the EE-docs. – BNetz Apr 27 '14 at 13:30
1

Try this:

display_by="day" limit="30" 

EE-docs for display-by-parameter

EDIT: It seems that the limit-parameter in the example above does NOT limit to 30 absolute days (and so will show entries from the last 30 days), but it will count days on which entries have been posted. So if you use limit="30" it will show all entries from the last 30 days on which entries have been posted.

| improve this answer | |
0

For a link list, you can query the database directly for title and url_title
(add some extra criteria to control returned data)

{exp:query sql="
  SELECT title, url_title, view_count_one 
  FROM exp_channel_titles
  WHERE status != 'closed'
    AND entry_date > {current_time} - 2592000 /* 30 * 24 * 60 * 60 = 30 days */
    /* AND channel_id = xxx */
    /* AND view_count_one > 0 */
  ORDER BY view_count_one DESC
  LIMIT 7
"}
  <a href="/news/entry/{urltitle}">{title}</a> ({view_count_one})<br>
{/exp:query}

If you want full-fledged channel entries output (e.g. custom fields etc.),
you can select just the entry_id's and pass the result to an embed.
The zero is just a quick way to close the series. e.g. 12, 34, 0
otherwise you'ld have to use {entry_id}, with backspace=1.

{embed="group/entriestemplate" which="{exp:query ...}{entry_id},{/exp:query} 0"}

<!-- embed -->
{exp:channel:entries entry_id="{embed:which}" ...}
...
{/exp:channel:entries}
| improve this answer | |
0

Could you not just use the start_on parameter and set the start date to 30 days prior to the current date?

https://ellislab.com/expressionengine/user-guide/add-ons/channel/channel_entries.html#start-on

| improve this answer | |
0

There are 4 options you have for tracking the views, view_count_one, view_count_two, view_count_three, view_count_four. Basically we use view_count_one for our purpose, so here we can use view_count_two or three or four for tracking the hits and then create a simple plugin which will refresh the count value to '0'. And use that plugin on any template and set template URL to the cron after every 30 days.

So that after every 30 days the track_view_two, three or four will be flush to 0 and you can simply use to show the entries orderby="view_count_two or _three or _four".

plugin code should be look like this: - public function view_count_four() { $qry = $this->EE->db->update('channel_titles', array( 'view_count_two' => '0' ), array( 'channel_id' => '21' ) ); } and when you show the data on any template, {exp:channel:entries channel="brands" track_views="two" limit="10" orderby="view_count_two" dynamic="off" }

| improve this answer | |

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.