Album Thumbnail instead Album Title on album page

perica6892

Joined: 2009-08-02
Posts: 12
Posted: Sun, 2009-08-02 18:08

Hello,

I've installed Gallery2 a few days ago and I was instantly impressed with it's features.

I've started with Matrix theme and customized it almost to the point how I want it.

You can check the gallery here http://www.parasole.rs/gallery/main.php

The only thing left to do is to make Album Thumbnail as is on the main page to be displayed instead of
Album Title when you enter that album.

I've searched the forums and couldn't find the answer.

Can someone point me to the topic which cover this, if it exists on the forums, or at least give me
some hints how to achieve this.

Thank you!

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Mon, 2009-08-03 05:18

Can you post a screenshot or mockup of what you're looking for. I'm not sure what you want changed.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Mon, 2009-08-03 12:40

Hi nivekiam, thank you for reply.

If you visit the url I posted in first message, you will see main (root) gallery.

Click any of the galleries, for example "Audi", and you can see name of the gallery
"Audi" centered above images.

I would like instead of that to be album thumbnail, which in this case is Audi logo,
as is in the root gallery.

Here is the picture of what I want to achieve, logo in red square in first image should
be in place of red square in second picture.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Mon, 2009-08-03 13:58

We don't have access to anymore info about the parent besides its id.
You'd have to add the extra parameter to theme.inc.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Mon, 2009-08-03 14:17

Hmm, if ID of the parent is known, how can I get it's thumbnail based on that?
I see it's possible to get parent's name, so I suppose this should be possible too.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Mon, 2009-08-03 15:32

Hmm, sorry my bad, it would be $theme.item, not $theme.parent - but the thumbnail is still not available(at least in carbon).

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Mon, 2009-08-03 15:39

And I don't think Carbon is that different from Matrix. If you put Gallery into Debug Mode, you can see a Smarty Debug popup window that will show you everything that's currently available on any page.
FAQ: How to set/use Gallery in debug mode?
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 13:31

Thanks for you replies.

I found that I could use GalleryCoreApi::fetchThumbnailsByItemIds($itemId)

but I'm a bit off from there.

Where should I put that line in order to retrieve a thumbnail based on album ID?

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Tue, 2009-08-04 14:02

in theme.inc function showAlbumPage after $theme =& $template->getVariableByReference('theme');
add:

    list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($item->getId()));
    if (!$ret && ! empty($thumbnail)) {
        $theme['item']['thumbnail'] = $urlGenerator->generateUrl(array('view'=>'core.DownloadItem', 'itemId'=>$thumbnail[$item->getId()]->getId(), 'serialNumber'=>$thumbnail[$item->getId()]->getSerialNumber()), array('forceFullUrl'=>true, 'forceSessionId'=>true, 'htmlEntities'=>true));
    }
    if ($ret) {
        return array($ret, null);
    }

this will make $theme.item.thumbnail available in album.tpl
untested.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 14:22

Not working by just copying and pasting.

After adding the code to theme.inc and <center>{$theme.item.thumbnail}</center> into album.tpl

I get an HTML 500 internal server error when I try to load the page...

Am I missing something here?

As a side note, I don't know if this matters, album thumbnail is not an image from the album, I added it as Custom album thumbnail.

Thank you very much for your time suprsidr

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 14:30

I tried this

list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($item->getId()));

$theme['item']['thumbnail'] = $thumbnail[$item->getId()]->getId();

if ($ret) {
return array($ret, null);
}

And it's returning 49 when calling $theme.item.thumbnail

But, when looking in address bar of my browser I see

http://www.parasole.rs/gallery/main.php?g2_itemId=29

Shouldn't it show 29?

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 14:33

My bad, 49 is actually id of the thumbnail :) Now I'm getting somewhere

Then, my best guess, the error is somewhere in this line

$theme['item']['thumbnail'] = $urlGenerator->generateUrl(array('view'=>'core.DownloadItem', 'itemId'=>$thumbnail[$item->getId()]->getId(), 'serialNumber'=>$thumbnail[$item->getId()]->getSerialNumber()), array('forceFullUrl'=>true, 'forceSessionId'=>true, 'htmlEntities'=>true));

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Tue, 2009-08-04 14:35

The thumb's id is different then the actual album's id.
I'll actually test it out on mysite.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Tue, 2009-08-04 14:39

I'm generating the actual thumbnail url so in the template you would use <img src="{$theme['item']['thumbnail']}"/>

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 14:42

When I try to right click the thumbnail and copy/paste it's address

http://www.parasole.rs/gallery/main.php?g2_view=core.DownloadItem&g2_itemId=49&g2_serialNumber=5

it takes me to the right picture.

I don't know what is causing the error here.

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 14:48

Not working, I can't even get the url to show up as a string...

Again, this is what I have in theme.inc

Quote:
$theme =& $template->getVariableByReference('theme');

list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($item->getId()));

$theme['item']['thumbnail'] = $urlGenerator->generateUrl(array('view'=>'core.DownloadItem', 'itemId'=>$thumbnail[$item->getId()]->getId(), 'serialNumber'=>$thumbnail[$item->getId()]->getSerialNumber()), array('forceFullUrl'=>true, 'forceSessionId'=>true, 'htmlEntities'=>true));

if ($ret) {
return array($ret, null);
}

And now I'm calling it from album.tpl with

Quote:
<center><img src="{$theme.item.thumbnail}" /></center>

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 6136
Posted: Tue, 2009-08-04 14:58

Sorry, I was getting a little sloppy:

global $gallery;
    $urlGenerator = &$gallery->getUrlGenerator();
    $itemId = $item->getId();
    list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($itemId));
    if (!$ret && ! empty($thumbnail)) {
        $theme['item']['thumbnail'] = $urlGenerator->generateUrl(array('view'=>'core.DownloadItem', 'itemId'=>$thumbnail[$itemId]->getId(), 'serialNumber'=>$thumbnail[$itemId]->getSerialNumber()), array('forceFullUrl'=>true, 'forceSessionId'=>true, 'htmlEntities'=>true));
    }
    if ($ret) {
        return array($ret, null);
    }

and then in album.tpl
<img src="{$theme.item.thumbnail}"/>

works for me.
-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 15:04

I thought it had something to do with not defining what $urlGenerator was, but I didn't want to pretend smart :)

I managed to display the thumbnail by simple string concatenation

$theme['item']['thumbnail'] = 'http://www.parasole.rs/gallery/main.php?g2_view=core.DownloadItem&g2_itemId='.$thumbnail[$item->getId()]->getId().'&g2_serialNumber='.$thumbnail[$item->getId()]->getSerialNumber();

But your approach is universal, now I'll test it.

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 15:08

And it works perfectly.

Thanks a bunch suprsidr

 
perica6892

Joined: 2009-08-02
Posts: 12
Posted: Tue, 2009-08-04 15:44

As a thank you, I'm writing the tutorial how to do this in case other users need this too.

NOTE: This tutorial is based on default Matrix theme and if you are using another theme things might be slightly different, but in general this should work for all the themes, only line numbers should be different.

HOW TO DISPLAY ALBUM THUMBNAIL INSTEAD OF ALBUM TITLE

By default, G2 is set to display album name on top of the page when browsing through the galleries.

If you want to change this behaviour, and display album's thumbnail instead, this is what you should do:

- Open the file theme.inc located under /[YOUR GALLERY2 INSTALL DIR]/THEMES/[YOUR THEME]/

- Find the code

$theme =& $template->getVariableByReference('theme');

on approx. line 71

- After that line paste the following code

/*Custom code by suprsidr to enable album thumbnail*/
	
global $gallery;
	
$urlGenerator = &$gallery->getUrlGenerator();
	
$itemId = $item->getId();
	
list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($itemId));
	
if (!$ret && !empty($thumbnail)) {
    $theme['item']['thumbnail'] = $urlGenerator->generateUrl(array('view'=>'core.DownloadItem', 'itemId'=>$thumbnail[$itemId]->getId(), 'serialNumber'=>$thumbnail[$itemId]->getSerialNumber()), array('forceFullUrl'=>true, 'forceSessionId'=>true, 'htmlEntities'=>true));
}
	
if ($ret) {
    return array($ret, null);
}
/*end of custom code*/

- Save theme.inc

- Open up the album.tpl located under /[YOUR GALLERY2 INSTALL DIR]/THEMES/[YOUR THEME]/TEMPLATES/

- Find this line of code

<h2> <center>{$theme.item.title|markup}</center> </h2>

- Replace this line with the following code

<img src="{$theme.item.thumbnail}"/>

- Save album.tpl

- That's it. now you should see album's thumbnail instead of it's name showing up as the gallery title.

 
Kevin L. Rivera

Joined: 2010-02-11
Posts: 1
Posted: Thu, 2010-02-11 04:45

To perica6892, thanks

After your post established Galery2 and was pleasantly surprised by its features:)

Best regards