TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,231
  • Total Topics: 21,353
  • Online today: 606
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 479
  • Total: 479

Greeting Block

Started by rjackson, April 22, 2006, 03:24:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

rctxtreme

$hour = date('G') + $user_info['time_offset'];
  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24;

if($hour >= 0 && $hour <= 7)
{
        echo 'Very early, isnt it,' . $user_info['username'] . '?';
}
else if($hour <= 8 && $hour <= 12)
{
        echo 'Good morning,' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
        echo 'Good afternoon,' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
        echo 'Good evening,' . $user_info['username'] . '!';
}

Ain't working, this code.

JPDeni

You need to add global $user_info; at the beginning and a } at the end of line 3. You'll also want to add a space after each of your commas so that your text looks right. Here's the correct code, all put together:

global $user_info;

$hour = date('G') + $user_info['time_offset'];
  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24; }

if($hour >= 0 && $hour <= 7)
{
        echo 'Very early, isnt it, ' . $user_info['username'] . '?';
}
else if($hour <= 8 && $hour <= 12)
{
        echo 'Good morning, ' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
        echo 'Good afternoon, ' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
        echo 'Good evening, ' . $user_info['username'] . '!';
}


This was copied directly from a block on my site that works just fine. If it doesn't work on your system, you've probably got something else conflicting with it.

Crip

The above looks good.. thanks for the space after comma info. 8)
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



rctxtreme

Great! Thanks. If only it looked like this to an admin:
Good morning, rctxtreme
PM: 1
Show unread
Show replies
Show own posts

Modules
Downloads

Tools
Upload file
Manage settings
Manage blocks
Manage articles
Manage Downloads

JPDeni

It can, but you have to edit the TPortalBlocks.template.php file.

Here's what I did. Down at the bottom of the file, I added
function greeting()
{
  global $user_info;
  $return = '';
  $hour = date('G') + $user_info['time_offset'];
  if ($hour > 23) { $hour = $hour - 24; }
  elseif ($hour < 0) { $hour = $hour + 24; }
  $name = $user_info['username'];
  if($hour >= 0 && $hour <= 7)
  {
        $return = "Very early, isnt it, <b>$name</b>?";
  }
  else if($hour <= 8 && $hour <= 12)
  {
        $return =  "Good morning, <b>$name</b>!";
  }
  else if($hour >= 13 && $hour <= 16)
  {
        $return =  "Good afternoon, <b>$name</b>!";
  }
  else if($hour >= 17 && $hour <= 23)
  {
        $return =  "Good evening, <b>$name</b>!";
  }
  return $return;
}


Then under function userbox(), find

                echo '<span class="normaltext">
                                                        ', $txt['hello_member'], ' <b>', $context['user']['name'], '</b></span>';


Change it to

                echo '<span class="normaltext">
                                                        ', greeting(), '</b></span>';


It works for me.

rctxtreme

Seems to me that it doesn't contain the modules, tools sections. Does it? If it does perhaps you should show me an example

JPDeni

#26
The userbox is what contains all the other stuff in the box.

Here's a screenshot of mine from this morning.

(I don't have the download module active, so that's not part of the box.)

rctxtreme


Bobbyplant

Quote from: rjackson on April 22, 2006, 03:24:48 PM
I found this little bloc on a site, you can set a greeting message to display based on the time of day it is.

--------------------------------------------------------
<?php

$hour = date('G');

if($hour >= 0 && $hour <= 7)
{
        echo 'Very early, isnt it?';
}
else if($hour <= 8 && $hour <= 12)
{
        echo 'Good morning!';
}
else if($hour >= 13 && $hour <= 16)
{
        echo 'Good afternoon!';
}
else if($hour >= 17 && $hour <= 23)
{
        echo 'Good evening!';
}

?>

Hi sorry to sound silly but as im not clued up on adding blocks or anything to the front page. How do i add this?? Please excuse my ignorance.


This website is proudly hosted on Crocweb Cloud Website Hosting.