Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
850 views
in Q2A Core by

How to make Shorting view count, like 2000 to 2k

Q2A version: Latest 1.6 dev

2 Answers

+5 votes
by
selected
 
Best answer

This Code Works With 1.6dev paste this in theme file

function q_item_stats($q_item) // add view count to question list

{
$this->output('<DIV CLASS="qa-q-item-stats">');
$this->voting($q_item);
$this->a_count($q_item);
$this->output('<DIV CLASS="qa-view-count">');
$this->output( 
                '<SPAN CLASS="qa-view-count-data">', 
                $this->short_num($q_item['raw']['views']), 
                '</SPAN>' 
            ); 
$this->output('<span class="qa-view-count-pad">views</span>');
$this->output('</DIV>');
$this->output('</DIV>');
}
 
function view_count($q_item) // prevent display of view count in the usual place
{
}
 
function short_num($num, $precision = 1) { 
           if ($num >= 1000 && $num < 1000000) { 
            $n_format = number_format($num/1000,$precision).'K'; 
            } else if ($num >= 1000000 && $num < 1000000000) { 
            $n_format = number_format($num/1000000,$precision).'M'; 
           } else if ($num >= 1000000000) { 
           $n_format=number_format($num/1000000000,$precision).'B'; 
           } else { 
           $n_format = $num; 
            } 
          return $n_format; 
        }

 

by
perfect - first 2 function should be override...
+1 vote
by
by
thanx but its not working ....in my 1.6 dev
     function q_item_stats($q_item)
        {
            $this->output('<DIV CLASS="qa-q-item-stats">');
             
            $this->voting($q_item);
            $this->a_count($q_item);
            $this->output(
                '<SPAN CLASS="q-list-points">',
                $this->short_num($q_item['raw']['views']),
                '</SPAN>'
            );
            
        }
it breaks my whole theme
...