MyBB Community Forums

Full Version: Add greetings in welcome block according to the time of the day
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Go to: ACP > Templates > Header Templates > header_welcomeblock_member > and find;
{$lang->welcome_back}

and before it, add the following;
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Robert Ison -->
<!-- Web Site:  http://www.infosourcetraining.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("<b>Good " + display + "!</b>");
document.write(greeting);
//  End -->
</script> - 

Should result into this;
[Image: attachment.php?aid=102]
[Image: attachment.php?aid=101]
[Image: attachment.php?aid=100]
If one wants to use different languages or greetings depending on language settings, one can also insert the script code *inside* the language variable (in global.lang.php) Wink
(2011-04-19, 08:21 AM)linguist Wrote: [ -> ]If one wants to use different languages or greetings depending on language settings, one can also insert the script code *inside* the language variable (in global.lang.php) Wink

Didn't tested it on global lang file.
(2011-04-19, 08:21 AM)linguist Wrote: [ -> ]If one wants to use different languages or greetings depending on language settings, one can also insert the script code *inside* the language variable (in global.lang.php) Wink

Yes, you can use PHP in the language files, as it are just PHP files.

In global.lang.php
$l['welcome_back'] = "<strong>Good ".(my_date("G","","",false) > 17 ? "evening " : (my_date("G","","",false) > 12 ? "afternoon" : (my_date("G","","",false) > 6 ? "morning" : "night"))).", {1}</strong>. You last visited: {2}";
Great idea.

I assume this works according to the forum's time settings?
(2011-04-19, 10:33 AM)faviouz Wrote: [ -> ]I assume this works according to the forum's time settings?

My modification works according to the time settings from the current user on your forum, yes. You can test it by changing the timezone in your UserCP.
Yaldarim's modification works according to the browser's time settings.
(2011-04-19, 10:40 AM)Aries-Belgium Wrote: [ -> ]Yaldarim's modification works according to the browser's time settings.

Typo Mistake Toungue
Nice tutorial!
Thanks.
Hi,

I'm using this, and I have a 24 hour clock, only problem is me and some other people are getting this:

- ,George! - You last visited: Today, 19:47 PM (User CP — Mod CP — Log Out)

I believe it's only in the evenings, any ideas why?


welcomeblock_member template:
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Robert Ison -->
<!-- Web Site:  http://www.infosourcetraining.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("<b>Good " + display + "!</b>");
document.write(greeting);
//  End -->
</script> -

,{$lang->welcome_back} (<a href="{$mybb->settings['bburl']}/usercp.php"><strong>{$lang->welcome_usercp}</strong></a>{$modcplink}{$admincplink} &mdash; <a href="{$mybb->settings['bburl']}/member.php?action=logout&amp;logoutkey={$mybb->user['logoutkey']}">{$lang->welcome_logout}</a>)<br />
				<span class="links">
					<a href="#" onclick="MyBB.popupWindow('{$mybb->settings['bburl']}/misc.php?action=buddypopup', 'buddyList', 350, 350);">{$lang->welcome_open_buddy_list}</a>
				</span>
				<a href="{$mybb->settings['bburl']}/search.php?action=getnew">{$lang->welcome_newposts}</a> | <a href="{$mybb->settings['bburl']}/search.php?action=getdaily">{$lang->welcome_todaysposts}</a> | <a href="search.php?action=finduserthreads&uid={$mybb->user['uid']}">View my threads</a> | <a href="search.php?action=finduser&uid={$mybb->user['uid']}">View my posts</a> | <a href="{$mybb->settings['bburl']}/private.php">{$lang->welcome_pms}</a> {$lang->welcome_pms_usage}
Pages: 1 2