We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38799
    • 5 Posts
    Hey Everyone,

    I have spent the better part of 2 days searching the forums, packages and add-ons page looking for a solution that works in Revo 2.x. I am a veteran with Evolution but this is my first install of Revolution.

    I have been looking for a Top Viewed or Most Requested Pages listing snippet for a few days now. I read a lot of posts and articles that talk about the PageHits snippet in the package manager. It seems the in Evo someone named Susan came up with an snippet called Page Hits Counter Results and it would use the PageHits table data to create a list of resources based on the number of hits it had received.

    The problem is I can't make it work in Revo apparently due to the changes in core processing.

    Does anyone know if there is a new snippet for Revo that creates a "Most Viewed" list?

    OR, does anyone know how to modify this code to work in Revo?

    //Developed by David Bunker (bunk58) 28/08/08
    //Requires the PageHitCounter 2.0 by Susan Otwell (http://modxcms.com/repository-upload.html?repotype=addition&resourceid=878)
    //Create a new snippet named PHCResults
    //Copy & Paste the code below into it
    //The snippet takes 4 parameters:
    //&excludeIDs => default = 0 , a comma seperated list of document ID's to exclude from the results (might be useful for 404 pages, Home page etc.)
    //&limit => default = 5 , maximum number of results
    //&table_prefix => default = modx_ , your database prefix if different to modx_
    //&tpl => default = top_pages , name of template chunk for sidplaying the results
    //Example call => [!PHCResults? &excludeIDs=`1,2,3` &limit=`10` &table_prefix=`custom_` &tpl=`your_tpl`!]
    //The example template chunk below lists the four placeholders available
    //Example template chunk => 
    //<p>Total Hits = [+phc.count+] for <a href="[~[+phc.pageID+]~]" title="[+phc.title+]">[+phc.longtitle+]</a> - [+phc.description+]</p>
    //Copy & Paste the above into a chunk and name it top_pages or create your own
    //Here's the snippet code =>
    
    $table_prefix = (isset($table_prefix)) ? $table_prefix : 'modx_';
    $limit = (isset($limit)) ? $limit : 5;
    $excludeIDs = (isset($excludeIDs)) ? $excludeIDs : '0';
    $tpl = (isset($tpl)) ? $tpl : 'top_pages';
    $output = '';
    $sql = mysql_query('SELECT * FROM `'.$table_prefix.'pagehits`, `'.$table_prefix.'site_content` WHERE '.$table_prefix.'pagehits.resource_id='.$table_prefix.'site_content.id AND '.$table_prefix.'site_content.id NOT IN('.$excludeIDs.')ORDER BY `page_count` DESC LIMIT '.$limit.'');
    $resultArray = $modx->db->makeArray( $sql );
    foreach($resultArray as $item)
    {
    $params['phc.count']=$item['page_count'];
    $params['phc.pageID']=$item['page_id'];
    $params['phc.title']=$item['pagetitle'];
    $params['phc.longtitle']=$item['longtitle'];
    $params['phc.description']=$item['description'];
    $output.=$modx->parseChunk(''.$tpl.'', $params, '[[+', ']]');
    }
    return $output;


    Thanks for any help you can provide and I apologize if this has already been discussed many times, but if it has my search results have been fruitless.

    Bryan
      • 38799
      • 5 Posts
      Anyone have anything they can offer? I really need to get this working for our new website.

      Thanks!

      Bryan
        • 32316
        • 387 Posts
        found this with a google search: pageHits http://modx.com/extras/package/pagehits

        find in Package Management as PageHits
        and there is also an extra called HitsPage.

        One of these might be a good place to start or give you some ideas of how to build what you need.

        I have not tried either of these or looked at their code [ed. note: whistlemaker last edited this post 14 years, 7 months ago.]
          • 3749
          • 24,544 Posts
          The fastest and easiest method would be to store the hit count in one of the resource fields that you don't need for anything else (e.g. longtitle, introtext, description, uri) using a simple snippet. That way you could pull the most popular pages easily with getResources. The down side to that would be that you might later decide to use that field for its original purpose.

          Another method would be to use a 'HitCount' TV. It would still be relatively easy although the getResources call would be more complex and significantly slower.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 38799
            • 5 Posts
            Thanks, for the responses. I am using the Page Hits Counter found in the package manager, but that only counts the page hits. In Evo there was another snippet called Page Hits Counter Results which created a navigational list based on the number of hits in the Page Hits Counter (which is the code I pasted above). I need help with converting the code to work in Revo.

            Revo doesn't like:
            $modx->db->makeArray


            The help documentation says to "see xPDOCriteria" to replace the makeArray. I have tried a couple of different codes based on the information found here http://rtfm.modx.com/display/xPDO20/Retrieving+Objects but this is beyond my skill level at the moment.

            Any other help would be appreciated.