On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.

Answered PageHitCounter

Subscribe: RSS
  • My chunk X has the call:

    [[PHCResults? &excludeIDs=`1,26,29` &limit=`1` &tpl=`test`]]


    Template "test" has this:

    <p><i class="fa fa-eye"></i> [+phc.count+] for <a href="[~[+phc.pageID+]~]">[~[+id+]~]</a></p>
    


    Now the UNIQUE page title is shown, however the corresponding UNIQUE COUNT is NOT. I tried adding [~[+id+]~] in front of [+phc.count+] but that did not work. Is it possible to get the corresponding unique page view count number next to my title?

    UPDATE: Even though the correct page title is shown, when clicking the link it directs to another title (and its always the same title it directs to... sad - and that title is the one that has the MOST page-views, so the highest number of page views gets taken somehow always.

    That problem is here in the PHP snippet:
    <?php
    $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.'page_hit_counter`, `'.$table_prefix.'site_content` WHERE '.$table_prefix.'page_hit_counter.page_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;
    ?>


    >>>>>>>>>>>> How to NOT have it sorted by page count, but just display by my ID????

    http://modx.s3.amazonaws.com/extras/329/repo-2180.txt

    This question has been answered by breezer. See the first response.

    [ed. note: rbosos last edited this post 5 years, 2 months ago.]
    • discuss.answer
      I'm pretty sure that snippet is designed to show the top results of pageviews, is this snippet going to be used on each individual page? I think the following code will work for what you are trying to achieve. Create a new snippet with the code below, and call it where you want the count to appear, it only returns the number.

      [!page_view_count!]

      <?php
      /* page_view_count snippet
      
      * outputs the page hit count number for the page currently being viewed
      
      */
      $output ='';
      $count = $modx->db->getValue( 
                   $modx->db->select( 'page_count', $modx->getFullTableName( 'page_hit_counter' ), 'page_id="'.$modx->documentObject['id'].'"' );
      	
      if( $count ) {
      	$output =$count; 
      }
      return $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
      • Hi breezer,

        I created the snippet ... page_view_count

        and called it like this...
        <p><i class="fa fa-eye"></i> [+page_view_count+] <a href="[~[+id+]~]">[+pagetitle+]</a></p>


        But no number shows. If I use [!page_view_count!] then this shows frontend... [!page_view_count!] only.

        I have Sotwell Page Hit Counter implemented... https://modx.com/extras/package/pagehitcounter and I can see the correct corresponding page views numbers in the module though.
        • Without being able to see how you have all this setup I really can't say why it won't work, if you can PM me a link to the site I'll have a look.
            xforum
            http://frsbuilders.net (under construction) forum for evolution