SMF Show "1k" POSTS instead of "1,000" posts in Board Index? E.G. 1k, 1M, 1B

Started by Wellwisher, April 20, 2015, 06:08:04 PM

Previous topic - Next topic

Wellwisher

I have seen facebook, twitter and other social media sharing buttons round their "Likes" & "Share" numbers to 1k, 1M, 1B and I would like to implement this method of rounding numbers off in smf simplemachines board index.

Here's an example of what I mean, for illustrative purposes:



This method is the way to go I feel. It gives themes, developers and members a much more grounded professional, clean & tidy look. Any help would be nice, I will even pay $5 for a beer or coffee to the member who provides me with a solution that works flawlessly here.  :) paypal only.

Apparently there is a mod for this, if so which one is it? Also a member has wrote this code but they are both unable to find it!

P.S thanks margarett for unlocking this thread and locking the other one! Hopefully it will help others out in the future. :D

margarett

Well, the logics are kinda easy. There is a better way to do it actually but I can't find out how I did it before, so I'll go the lazy man way ;D

So, eg, in BoardIndex.template.php, you have the display of all your boards. The post/topic count is this part:
// Show some basic information about the number of posts, etc.
echo '
</td>
<td class="stats windowbg">
<p>', comma_format($board['posts']), ' ', $board['is_redirect'] ? $txt['redirects'] : $txt['posts'], ' <br />
', $board['is_redirect'] ? '' : comma_format($board['topics']) . ' ' . $txt['board_topics'], '
</p>
</td>

So we can perform some easy math before, knowing that "floor" is the PHP function that returns the integer division, rounded down.
So, let's add before that:
$posts = $board['posts'];
$topics = $board['topics'];
if (floor($posts / 1000000) > 1)
$posts = floor($posts / 1000000) . 'M';
elseif (floor($posts / 1000) > 1)
$posts = floor($posts / 1000) . 'k';
if (floor($topics / 1000000) > 1)
$topics = floor($topics / 1000000) . 'M';
elseif (floor($topics / 1000) > 1)
$topics = floor($topics / 1000) . 'k';


Now, in the block of code above, we just need to replace "comma_format($board['posts'])" with $posts and "comma_format($board['topics'])" with $topics
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Steve

I'm confused. Is this a column you want to add to the board index? Mine doesn't show anything like that.

And btw, $5 for coffee is $5 wasted. Now beer, that's a different story ...

Edit: Forget my first sentence since Bruno answered. :P
DO NOT pm me for support!

Wellwisher

Just tested your lazy-man code locally.  I love it because it's short and to the point, it doesn't take up lines upon lines of code.

Weird, it doesn't seem to round-up posts/topic count if you have "child boards". It only seems to round up posts on single boards, help.  ;D

Wellwisher

EDIT: IGNORE LAST COMMENT, IT SEEMS TO ADD CHILDS TOO!

The code formats/ rounds post counts above 2k+ but not above 1k? 

I have post counts in single boards like:

1448, 1675, 1755 and they don't get formatted.

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Wellwisher

My dude, thank you so much. That addition solved the issue.  8) You ought to make a mod for this with extra added features and options such as "animate the numbers" with javascript as the user scrolls down them etc. Members will love this. Board indexs look even more beautiful on smaller screens. It's just a sexy piece of code, I love it. Please let me buy you a beer to say my thanks mate, please shoot me a pm.

Thank you margarett for everything. P.s your sig quote made me laugh. 

JBlaze

Hmm... this is simple enough that it could be added to 2.1 for smaller resolutions. Juuuuuust a thought ;)
Jason Clemons
Former Team Member 2009 - 2012

margarett

@Wellwisher I'm always up for a beer, but no need, thank you for the offer ;)
@zilladotexe, Github is waiting for you :P
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

JBlaze

Jason Clemons
Former Team Member 2009 - 2012

Advertisement: