Jump to content

sort by date


buothz
 Share

Recommended Posts

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

Link to comment
Share on other sites

You can find a list of built-in page fields here: http://processwire.com/api/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!

  • Like 2
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...