MyBB Community Forums

Full Version: Is there a variable for "Last post X minutes/hours/days ago"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone. I'm wondering if there is a variable that will show the last post in that thread in X minutes/hours/days/etc in showthread template?
I don't think you can easily. The showthread template is a composition of Post Bit Templates containing post date/time.
With some modification you may can grab the "lastpost_date" used in Forum Bit Template.

By editing the hard coded PHP, it is possible to read the last post date/time and make it available as variable for templates.

[ExiTuS]
(2019-10-24, 08:27 AM)[ExiTuS] Wrote: [ -> ]I don't think you can easily. The showthread template is a composition of Post Bit Templates containing post date/time.
With some modification you may can grab the "lastpost_date" used in Forum Bit Template.

By editing the hard coded PHP, it is possible to read the last post date/time and make it available as variable for templates.

[ExiTuS]

I've never really done hard coding with PHP, but I feel like maybe something like this is something I *possibly* can take on my own. I tried adding the following variable {$lastpost_date} to the template, but it unfortunately was not a solution.

If I were to hard code this to make it available as a variable, which file should I be working in, and would it be custom code, or basically swapping some code over from another file, and making the changes in that code?
Here you go!

Edit showthread.php (1.8.21)
Add the following line anywhere below(!) line 65. A good location is empty line 96:
$thread_lastpost_date = my_date('relative', $thread['lastpost']);
This will just create a new variable with the relative date format. You can rename it for sure.

Drop this variable wherever you want to your showthread[_*] templates:
{$thread_lastpost_date}

That's it Smile

[ExiTuS]
(2019-10-24, 09:36 AM)[ExiTuS] Wrote: [ -> ]Here you go!

Edit showthread.php (1.8.21)
Add the following line anywhere below(!) line 65. A good location is empty line 96:
$thread_lastpost_date = my_date('relative', $thread['lastpost']);
This will just create a new variable with the relative date format. You can rename it for sure.

Drop this variable wherever you want to your showthread[_*] templates:
{$thread_lastpost_date}

That's it Smile

[ExiTuS]

Incredible! Thank you!
Make notes to document changes you make. You will need to do them again when you upgrade forum. There's a plugin somewhere that helps, called Patches. I haven't used it myself, but I've seen references to it here and there.
(2019-10-24, 10:39 AM)HLFadmin Wrote: [ -> ]Make notes to document changes you make. You will need to do them again when you upgrade forum. There's a plugin somewhere that helps, called Patches. I haven't used it myself, but I've seen references to it here and there.

Thank you for this note. I will definitely need to put this down then for future upgrades and I will look into this Patches plugin as well. It sounds useful
1. Yes, keep all changes in mind Smile
For documentation purpose I used to write down all changes to the Administrator Notepad in ACP in addition.

2. When editing PHP core files, try to find empty space/lines for new code to avoid unnecessary line breaks. That makes you keep safe to reference on line numbers.

[ExiTuS]