MyBB Community Forums

Full Version: Where can I find {$thread['views']}
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Im trying to make changes to {$thread['views']} and cant seem to find a spot for it. any help?
May need to be more specific about what you're trying to do. Are you trying to edit the value, change a template?
sorry yes, Im trying to edit the views on threadlist template.

like change the way the views display and i need to find {$thread['views']} is what im looking for.
There is {$thread['views']} in forumdisplay_thread .

What change do you want?
(2023-02-17, 07:00 PM)tedem Wrote: [ -> ]There is {$thread['views']} in forumdisplay_thread .

What change do you want?

yes but I want to change what that displays
Display format? Like 1K instead of 1,000?
for example, on this particular forum if a post gets 1,200 views it displays 1.2 B I want to fix that it should be 1.2 K

(2023-02-17, 07:08 PM)tedem Wrote: [ -> ]Display format? Like 1K instead of 1,000?

exactlytlly yes

(2023-02-17, 07:08 PM)tedem Wrote: [ -> ]Display format? Like 1K instead of 1,000?

this also is not for your theme either Smile this is just for something else im doing for someone
You'd need a plugin for that (and there will already be one if it's doing it), you can't do that directly in the template. Unless it's being done by javascript.
Open ./inc/functions.php - add at the end:

function short_number($number)
{
    $units = ['', 'K', 'M', 'B', 'T'];

    for ($i = 0; $number >= 1000; $i++) {
        $number /= 1000;
    }

    return round($number, 1) . $units[$i];
}

Open ./forumdisplay.php:

Find: $thread['views'] = my_number_format($thread['views']);

Replace: $thread['views'] = short_number($thread['views']);

Here is the function I use for the Alpine theme.
(2023-02-17, 07:17 PM)tedem Wrote: [ -> ]Open ./inc/functions.php - add at the end:

function short_number($number)
{
    $units = ['', 'K', 'M', 'B', 'T'];

    for ($i = 0; $number >= 1000; $i++) {
        $number /= 1000;
    }

    return round($number, 1) . $units[$i];
}

Open ./forumdisplay.php:

Find: $thread['views'] = my_number_format($thread['views']);

Replace: $thread['views'] = short_number($thread['views']);

Here is the function I use for the Alpine theme.

Thanks, this was already setup for this forum just had to change the letters they used. this is exactlly what i needed
Pages: 1 2