MyBB Community Forums
Simple Greeting Message to visitors - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Resources (https://community.mybb.com/forum-8.html)
+--- Forum: Tutorials (https://community.mybb.com/forum-38.html)
+--- Thread: Simple Greeting Message to visitors (/thread-118550.html)



Simple Greeting Message to visitors - Krytic - 2012-05-10

Please note that this tutorial assumes that you know a very small amount of JavaScript. It's targeted towards beginners, since more advanced JavaScript coders could probably whip this out in a minute. Wink

This code is really simple - in the Header, if the user is visiting in the morning, a message saying "Good Morning!" will be shown, and if they are visiting in the afternoon/evening, a message saying "Good Afternoon!" will be displayed. This all refers to their timezone, not anything set by the board.

Okay. First you need to go to ACP>Templates and Style>Templates>Template Name>Header Templates>Header.

Now, you can add this script almost anywhere here, but as always, give thought to the style of your forum. I have an Apart style installed, and I have this message next to the "Search" button where it blends in nicely.

Now, add this code anywhere, but remember it will show up wherever you add it:
<p id="mywelcomemessage"></p>

<script type="text/javascript"><!--
var d = new Date();
var time = d.getHours();

if (time > 12) 
  {
  document.getElementById("mywelcomemessage").innerHTML="<strong>Good Afternoon!</strong>";
  }
else
  {
  document.getElementById("mywelcomemessage").innerHTML="<strong>Good Morning!</strong>";
  }
//-->
</script>

It's that easy! You now have a dynamic greeting that will respond to the user's clock, instead of responding to the board timezone.

I hope this helps you. Smile

Updated 26/09/12


RE: Simple Greeting Message to visitors - bestblackhatforum.com - 2012-05-11

The good thing about this plugin is it rely on the user's time zone. I think i might use this. Thanks.
Anyway do you know how to display the IP address of users whether guest or registered.
Something like this.
[Image: welcomeip.png]

It appear on the index.php upon visiting the site. Thanks.


RE: Simple Greeting Message to visitors - effone - 2012-06-12

Not working for me. It always says "Good Morning" Sad

OK, thats a keyword conflict, I think.

Replaced 'var time' with 'var n' and it worked Smile


RE: Simple Greeting Message to visitors - Krytic - 2012-09-26

I've updated this. Previously the code might've caused your entire forum to vanish, depending on where it was put. Now that risk is gone. Plus I used updated HTML - <strong> instead of <b>.