Gallery2:How to add custom stuff on main root page - Gallery Codex
Personal tools

Gallery2:How to add custom stuff on main root page

From Gallery Codex

If you want to display a custom message for your visitors on the main page, or just set a different layer, color, header or anything else, you will need to do this:

First, we need to know the id of the root album, in order to compare it with the current album id. We can get it by editing theme.inc of our current template. (The 'full' path is themes/<your theme>/theme.inc)
As we need this info on the album page, we need to put this inside function showAlbumPage(){ }.

/* get the rootId */
list ($ret, $rootId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
if ($ret) {
    return array($ret, null);
}

Okay, now we have the rootId as $rootId, let's compare it with the id of the current item ($item):

if ($item->getId() == $rootId) {
}

Great, we can insert anything into this if {} from now on.
We want to populate a variable, so we can use that later in the templates (.tpl files).

if ($item->getId() == $rootId) {
    $isItRoot = true;
}

There is only one thing to do, send this var to the template. It can be done with a single line as follows:
(Format is setVariable('nameInTheTemplate', $currentVariable) )

$template->setVariable('isItRoot', $isItRoot);

We are done with theme.inc. The code we had to add looks like this:

list ($ret, $rootId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
if ($ret) {
    return array($ret, null);
}
if ($item->getId() == $rootId) {
    $isItRoot = true;
}
$template->setVariable('isItRoot', $isItRoot);

Let's go and edit the template file now, and put our stuff in it. The template file we need now is called album.tpl. (The 'full' path is themes/<your theme>/templates/album.tpl)
Things get really easy here, we have the var $isItRoot, which is true in case of being on the root album, and false (or null) otherwise.
Let's print a simple hello message for visitors checking the main page of our gallery:

{if $isItRoot} Hi! Welcome in my gallery! {/if}

Cool, isn't it? ;)

If you want to combine it with checking if the user is registered ($user.isRegisteredUser) or just a guest ($user.isGuest), you can do easily, e.g.:

{if $isItRoot} 
  {if $user.isRegisteredUser}   
   Hello {$user.userName}, welcome on the main page!
  {else}
   Hello guest, welcome on the main page!
  {/if}
{else}
This is NOT the main page dude.
{/if}

etc :)

Note: this tutorial was made for Gallery 2.2. at 03/11/2007

Another method: http://galleryproject.org/node/70763#comment-255788