bnomei / kirby3-pageviewcounter

Track Page view count and last visited timestamp
https://forum.getkirby.com/t/kirby3-pageview-counter-track-page-view-count-and-last-visited-timestamp/23582
MIT License
22 stars 0 forks source link

Display in front end #4

Closed claraloustau closed 2 years ago

claraloustau commented 2 years ago

Hello, Thanks for your plugin ! Is there a way to display the counter in the front end ? Thanks

bnomei commented 2 years ago

hi. you can use the static method and forward the id of the page https://github.com/bnomei/kirby3-pageviewcounter/blob/c0f21cbf21a7084d75cc257b5e603363364f6bcb/classes/PageViewCounter.php#L65

in you template like default.php

<?php

echo \Bnomei\PageViewCounter::singleton()->count($page->id());
bnomei commented 2 years ago

fixed should have been \Bnomei\PageViewCounter::singleton()->count($id)

claraloustau commented 2 years ago

Thank you @bnomei !

claraloustau commented 2 years ago

Is there a way to make a sortBy() on the count($id) for a blog ? Something like : $mostclicks = $page->children->sortBy(\Bnomei\PageViewCounter::singleton()->count($id), 'desc');

claraloustau commented 2 years ago

Hello bnomei, is there a way to convert 1000 to 1k ? thank you

bnomei commented 2 years ago

try $formatedSize = I18n::formatNumber($count);