Jump to content

Build "badges" from field values of all pages


toni
 Share

Recommended Posts

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 of

A) 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

Bildschirmfoto 2019-12-24 um 14.21.45.pngBildschirmfoto 2019-12-24 um 14.21.24.pngBildschirmfoto 2019-12-24 um 14.20.12.png

Link to comment
Share on other sites

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. 

  • Like 3
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...