We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Is there a plugin or a snippet out there that lists the X most popular posts, similar to how the ListIndexer snippet works?

    This is a pretty standard thing for CMS’s... can anyone help a brother out?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Hmmm... not to my knowledge. I think this would need a snippet to access your stats program’s database (or files, or however it saves your stats). If you’re not using any stats software, you’ll need to make one that stores each page hit either in the database or in a file, then queries it to get the 10 most-hit documents. I wrote something along these lines a long time ago;

      http://modxcms.com/Page-Hit-Counter-878.html
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        That’s a good start... but the PageHitCounter module is essentially a back-end reporting tool. Are you recommending that I write a snippet that queries the page_hit_counter table?

        I can do that... but I’m wondering what the MODx way of doing that is... normally I would write my own database handle and put it in a directory above the root (e.g. in /lib instead of /public_html) and do a SQL statement something like:

        SELECT page_id FROM page_hit_counter ORDER BY page_count DESC LIMIT 10;
        

        or if I were feeling really saucy, I’d do something like:

        SELECT phc.page_id, sc.pagetitle FROM page_hit_counter phc INNER JOIN site_content sc ON phc.page_id=sc.id
        WHERE sc.hidemenu='0' ORDER BY phc.page_count DESC LIMIT 10;


        But this isn’t a good way to do it if I wanted to share this as a plugin with the community. Could someone point me at some example code where a snippet hits the database in a secure, quoted, prepared statement sort of way?

        Thanks.

          • 26681 MODX Staff
          • 123 Posts
          I know this is a super old thread, but this can be done easily in Revo:
          http://www.sepiariver.ca/blog/modx-web/modx-popular-posts-plugin-hit-counter-getresources
            [sepiariver.com] (https://sepiariver.com/)