Jump to content


Photo

sort by date

selectors

  • Please log in to reply
5 replies to this topic

#1 buothz

buothz

    Jr. Member

  • Members
  • PipPip
  • 45 posts
  • 3

Posted 18 April 2012 - 05:04 PM

I would like to sort the results page with
- The last 3 inserted pages
- The most visited pages
for the last three pages inserted I used the following code
$yachts = $pages->find("template=newyachts, limit=3, sort=-date");
foreach($yachts as $s) {...
The problem is that do not sort them by date... I do not know if you need to add a field "date", or it is generated automatically (as I thought I had read in the API).

Instead to select the most visited pages is there a way?

Thanks a lot...

#2 teppo

teppo

    Sr. Member

  • Members
  • PipPipPipPip
  • 388 posts
  • 384

  • LocationFinland

Posted 18 April 2012 - 11:11 PM

You can find a list of built-in page fields here: http://processwire.c...variables/page/. As you can see, "date" is not among them. What you seem to want here is "created."

If you need the value of that field to be easily editable later, you could also create your own date field and apply some magic to that -- check "Default to today's date", hide field and show when needed / show always and handle pages with date value cleared somehow etc.

Hope this helps!

tweets - code - modules


#3 teppo

teppo

    Sr. Member

  • Members
  • PipPipPipPip
  • 388 posts
  • 384

  • LocationFinland

Posted 19 April 2012 - 12:18 AM

Sorry, completely missed your other question, about most popular pages. I don't recall PW having anything like that built-in, but you could always build something of your own; every page load increase hit counter or something like that - although that seems a bit hacky to say the least.

If you need more sophisticated solution, you could always integrate with Google Analytics or some kind of Apache log parser, adding relevant statistic data to pages on a daily (nightly?) basis.

tweets - code - modules


#4 DaveP

DaveP

    Sr. Member

  • Members
  • PipPipPipPip
  • 285 posts
  • 135

  • LocationChorley, UK

Posted 19 April 2012 - 03:02 AM

Although I haven't done it myself, I understand that Piwik has an API you could use for page view counts and more.
Twitter : Facebook : GitHub : G+ : Blog : Powered by C8H10N4O2 and C10H14N2

#5 ryan

ryan

    Hero Member

  • Administrators
  • 5,771 posts
  • 3108

  • LocationAtlanta, GA

Posted 19 April 2012 - 01:35 PM

Just wanted to follow-up to say that there isn't anything built-in that can tell you what the most visited pages are. You could certainly add a hit counter field to a page and increment it, and save on every page view, but I think that would be kind of inefficient. It would also prevent you from using any cache features if you are having to save a page on every view. I think the best bet is to do what these guys suggested, or subscribe to a hit counter service that bundles this info into an RSS feed or JS widget.

#6 buothz

buothz

    Jr. Member

  • Members
  • PipPip
  • 45 posts
  • 3

Posted 19 April 2012 - 07:09 PM

thanks for all the answers, then as soon as I will post the code here also to helppeople who want to get my same results





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users