toni Posted December 24, 2019 Share Posted December 24, 2019 Hi, hope this is the right place to ask. Let's say next to others I have templates exhibition and news. Those templates have fields like: Title, author, files, startdate, enddate etc... For some fields I now want to show "tags" or "bages" similar to those attached to this issues at my sites frontend. Each badge should count the total values of some field of all pages. For example badge "Files" should count all files across pages with templates exhibition|news and onclick present a list with all files as links to its page.Solutions I can think ofA) Search for fields in question across pages, count the values and build an array with all links: for files this could look like: $all_files = $pages->find("template=exhibition|news, files>0"); foreach($all_files as $p) { print_r($p->files); // fill array with values // count results ... } The downside is this will be hard to manage, and maybe not quite performant? Thinking about using pro cache and maybe raw sql queries. B) Hook into page save, change, delete and update an array which I save in some textfield of a config page. This config page could be populated as api endpoint and return a full ready json object with count, links, titles etc. CON: More logic for building the array is needed, Pro: performance as the array is already built when a user visits the page? So long story short. This question is more about a start in the right direction. Thanks and merry christmas! Toni Link to comment Share on other sites More sharing options...
elabx Posted December 24, 2019 Share Posted December 24, 2019 1 hour ago, toni said: B) Hook into page save, change, delete and update an array which I save in some textfield of a config page. As an alternative so you don't have to use an extra field, you could also use the $cache API to save the counts, and to avoid the count on first load, calculate all counts when a page of template news or exhibition is saved through a hook. And if you really really want to make sure a guest user never hit the cache rebuild call you could use a cron job to rebuild the cache behind the scenes. 3 Link to comment Share on other sites More sharing options...
toni Posted December 25, 2019 Author Share Posted December 25, 2019 @elabx thanks a lot this is a nice idea! 1 Link to comment Share on other sites More sharing options...
dotnetic Posted December 26, 2019 Share Posted December 26, 2019 As another alternative to the find command, you could use @bernhard's RockFinder, which is much more performant than PW's PageFinder, as it only queries the fields you need. Link to comment Share on other sites More sharing options...
toni Posted December 26, 2019 Author Share Posted December 26, 2019 Nice option thanks Jens, thanks! Did not know of this plugin! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now