One way to do this is to create a function, insert_greeting() for example, and insert a call to it in each of your templates just ahead of the loop.
The function definition would look like this:
<?php function insert_greeting() {
global $userdata;
get_currentuserinfo();
$name = ($userdata->ID) ? $userdata->display_name : 'Guest';
echo "<h2>Hello, $name. Welcome to the site!";
}
?>
This function would be pasted at the end of the functions.php file in your theme folder. Be sure not to leave any blank lines before or after the definition.
The function call would look like this:
<?php insert_greeting(); ?>
In the default theme template index.php the call would look like this:
get_header(); ?>
<div id="content" class="narrowcolumn" role="main">
<?php insert_greeting(); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>