Set of Random Photo Thumbnails instead of Album Thumbs on main.php

Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Tue, 2009-08-18 03:19

Hi,

I'm using Gallery 2.3 with the Carbon theme.

Is there anyway to show a set of random thumbnails, say 3 from each album, on the main.php page instead of the album thumbnails, which is the default?

If that's not possible, then maybe the first three images in each album. When someone clicks on the thumb, they should get taken to the relevant album page with all thumbs showing for that album.

The three thumbs don't need to be next to each other, I just need to make sure enough images show up to make a good mosaic of small thumbnails on the main.php, which will take people to the appropriate albums.

I'm assuming it's in the theme.tpl...but after having a look I'm completely at a loss of what, where, or how!

I'm new to Gallery, so be gentle!

This is the set up so far...

I need to make sure I can do this before I go any further (hence I haven't added all the albums or pics yet) as my client definitely wants a mosaic wall of small thumbs on the Gallery entrance page, and as she only has 6 albums, the only way around it is to have a set of random thumbs taken from each album.

Cheers,

Tracy

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Tue, 2009-08-18 03:38

try the random highlight module: http://codex.gallery2.org/Gallery2:Modules:randomhighlight
or you can edit the root album and place the imageblock in your customized theme or some other similar plugin from:
http://www.flashyourweb.com/staticpages/index.php?page=mediaBlock or similar.

See this: http://codex.gallery2.org/Gallery2:Themes:How_to_Copy_an_Existing_Theme about customizing/creating your own theme. and placing things on the root album:
http://codex.gallery2.org/Gallery2:How_to_add_custom_stuff_on_main_root_page

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Tue, 2009-08-18 11:04

Hi,

I visited the mediaBlock website and downloaded it last night, but I thought it was only for putting things in the sidebar or side columns. I want the random photo pics in the 'main area' of the main.php (if that makes sense). I'll take a look at the plugin more closely.

I also downloaded the imageBlock, but that also appears to be for the sidebar rather than the main area of the theme.

I have to say I was hoping it would be more of an if/else php statement I could just stick somewhere in the theme.tpl or wherever.

I've got a feeling this could take me some time as I familiarise myself with the code. I'm used to working with Wordpress and Xoops, but Gallery2 is all new to me.

Thanks for the links.

Cheers,

Tracy

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Tue, 2009-08-18 13:37
Quote:
in the 'main area' of the main.php (if that makes sense). I'll take a look at the plugin more closely.

You're going to need to get into editing themes then. main.php is just some code to help gallery run, it has absolutely nothing to do with the page layout, look, feel, etc of Gallery. I see you mention theme.tpl so I see you're already looking at that.

Take a longer look at theme.tpl, it's laid out like your standard HTML page, only it has a lot of Smarty markup code (the template engine used in G2). You could pretty easily take the code for mediablock or imageblock and put then in the part of the page you want there.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Tue, 2009-08-18 14:32

Yes, nivekiam, I think it's the Smarty code that's befuddling me...

It sounds as though mediaBlock is in front at the moment for what I need, so I will delve into that this evening.

I'll be back... no doubt in a panic when I do something drastically wrong ;)

Cheers,

Tracy

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Tue, 2009-08-18 15:50

Just make backups and ask when you have questions. Read this too
http://codex.gallery2.org/Gallery2:Editing_Templates
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 03:15

Hi,

Okay...I'm stuck!

I have no idea where to put the code in the album.tpl for mediaBlock to replace the list of album thumbs on the root album, ie I want it to show the 40 micro-thumbs instead of the 6 album thumbs when people first enter the gallery2 site.

I've edited the mediablock.php and uploaded to gallery2/ directory.

I've edited the theme.inc file with the $isitroot stuff.

Quote:
/**
* @see GalleryTheme::showAlbumPage
*/
function showAlbumPage(&$template, $item, $params, $childIds) {
$ret = $this->loadCommonTemplateData(
$template, $item, $params,
array('owner', 'viewCount', 'childCount', 'descendentCount', 'parents',
'systemLinks', 'itemLinks', 'itemSummaries', 'permissions',
'thumbnails', 'pageNavigator', 'jumpRange'),
$childIds);
if ($ret) {
return array($ret, null);

}

/* Add in our extra stuff */
$theme =& $template->getVariableByReference('theme');
$theme['columnWidthPct'] = floor(100 / $params['columns']);

/* Check for JavaScript warning flag */
if (GalleryUtilities::getRequestVariables('jsWarning') != null) {
$template->setVariable('jsWarning', true);
}

/* Add our header and styles */
return array(null, 'theme.tpl');

/* get the rootId */
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);

}

I've tried the following in album.tpl

Quote:
{else}
{assign var="childrenInColumnCount" value=0}
<div class="gsContentAlbum">
{if $isItRoot} <?php @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=7&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');?>{/if}
</div>
{/if}
</div>

...and everything seems to be there, but no thumbs are showing.

Looking at the source code in the browser, it's showing the gsContentAlbum div but with nothing in it.

I also wonder if mediaBlock is going to do what I originally wanted. ie, to take a few random photos from each album.

Looking at the parameters for mediaBlock, it only seems to have the choice of using g2_itemID being that of a single item or an album. I've set this to 7, as that appears to be my rootalbum id. Is this correct?

Help appreciated.

Cheers,

Tracy

EDIT: It's also using the media block on all album pages, but I only want it on the root album (ie the gallery2 entry page). I'm assuming this is because I've deleted something I shouldn't have done on the album.tpl.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Thu, 2009-08-20 03:10

Try adding {php}
http://www.smarty.net/manual/en/language.function.php.php

Quote:
{if $isItRoot} <?php @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=7&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');?>{/if}

Not sure if this is going to work exactly like this, but try:

Quote:
{if $isItRoot} {/php}<?php @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=7&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');?>{/php}{/if}

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 03:24

No, that didn't work. It got rid of everything under the header, ie no album title, description, sidebar, etc.

I've just tried putting some plain text with the {if $isItRoot} {/if} and that didn't show either, although everything else is there again.

Which points to that being the problem. Any ideas? Could it be where I've placed it? Do I need to delete anything else off the album.tpl or something? Or maybe I've added it to the wrong place on the theme.inc file (I've pasted the code above).

Cheers,

Tracy

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Thu, 2009-08-20 03:40

Instead of your "isItRoot" stuff, try something like this:
{if $theme.item.parentId == 0}

I'm pretty sure that will work as only the root album will have a parent that has an id of 0.

___________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 03:40

Freelancealot,
see if you can back out all your changes.
then edit album.tpl like this:
http://gallery.menalto.com/node/70763#comment-255788
see if you can get text to work first.
If you get that then we can go to the next step.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 04:00

Hi Floridave,

I've reverted back to the default carbon album.tpl already. I'll just do the theme.inc file in a second.

But where do I put the

Quote:
{if empty($theme.parents)}
{if $theme.pageType != 'admin'}
stuff on root album only and not a admin page
{/if}
{/if}

in the template file???

I'm taking it that I don't need to delete anything from the album.tpl file just add the above somewhere...

Thanks for the help. Really appreciated.

Cheers,

Tracy

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 04:07

Yes edit album.tpl
place it close to where you want the images to show up.
I would suggest:

	      </div>
	      {else}
here
	      {assign var="childrenInColumnCount" value=0}

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 04:31

Okay...now we're getting somewhere :)

The text appeared on root album and not in other albums. However, the album thumbs are still showing on the root album page. So now I need to get the mediaBlock stuff in there to replace the usual album thumbs:

So I've now got:

Quote:
</div>
{else}
{if empty($theme.parents)}
{if $theme.pageType != 'admin'}
<?php @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=33&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');?>
{/if}
{/if}

{assign var="childrenInColumnCount" value=0}

But nothing is showing but the usual album thumbs.

When you look at the source code you can see that it's actually showing the <?php @readfile....?> line.

I've tried nivekiam smart {/php} thing, but again everything just disappeared below the horizontal menu.

Any ideas? I feel like I must be very close...!!

Cheers,

Tracy

Edit: Just in case, the permissions on mediablock.php are 744. Do I need to change that?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 04:36

Does this work take:
<?php @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=33&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');?>
and change to
{php} @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=33&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');{/php}

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 04:37
 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 04:43

It's doing something, but I'm not sure what.

It's now showing the word 'array' above the usual album thumbnails, but no mediaBlock stuff.

It's not showing the <php line when you view the source code in the browser any more BTW.

Cheers,

Tracy

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 05:11

Good tip...

I went to http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=33&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40 and it's just got a blank page with the word 'array' on it. (I am replacing 'www.mysite.com' with the proper site, just in case you were wondering... ;)

Aha, does that mean it's a problem with the actual mediaBlock.php or with the url and parameters?

I didn't change anything on the mediaBlock.php file because

Quote:
/* Connect to gallery */
function init (){
require_once( 'embed.php');
$ret = GalleryEmbed::init(array('fullInit' => true, 'embedUri' => '/gallery2/main.php', 'g2Uri' => '/gallery2/'));
if ($ret) {
print 'GalleryEmbed::init failed, here is the error message: ' . $ret->getAsHtml();
exit;
}
GalleryEmbed::done();
}

all seemed to be okay for my set up.

Gee I'm glad you're there, but where are you at this time...it's 5:50am here in the UK and I've been up all night trying to get this to work...so I'm very grateful for your help.

T.

Edit: By that I mean, it must be getting late where you are floridave. I'm going to see if I can get any answers from the mediaBlock site. But if you think of anything, please let me know.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 05:09
Quote:
...
just got a blank page with the word 'array' on it. (I am replacing 'www.mysite.com' with the proper site, just in case you were wondering... ;)

I guess you need to sort that out first.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16503
Posted: Thu, 2009-08-20 05:09

Do you have the Dynamic Albums plugin installed? I'm not sure, but it looks like that needs to be installed to use the dynamic stuff for mediaBlock.

Yep, looking at the mediaBlock code, it needs that plugin installed to do the random and dynamic stuff.

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 05:13

Doh! I'm installing it now.... how embarrassing is that...

I'll let you know if that does it. Back in a mo.

Cheers,

T.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 05:15

Also
......mediaBlock.php?g2_itemId=33&mode=dynamic.....
do you have a album with a ID of 33?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 05:24

ooohhhh....it works.... I feel really stupid now. However, I had no idea where to put the code on the album.tpl so you've all been a big help.

One last thing though... it's still showing the main album thumbs - how do I get rid of these on the root album page only?

Cheers,

T.

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 05:25

I changed that as well to the root album id, which was 7.

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 05:28

Just checking....

When you click one of the mediablock thumbs the url is http://www.mysite.com/gallery2/main.php?g2_itemId=54&g2_GALLERYSID=TMP_SESSION_ID_DI_NOISSES_PMT is there anyway to clean this up. I have the url rewrite mod loaded.

Cheers,

Tracy

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 06:24

Hi,

I'm almost there...just need to get rid of the album thumbs on the root album page (gallery2 entry page)

Below in bold is the bit I've added to the album.tpl, but this isn't get rid of the default album thumb display.

Quote:
</div>
{else}
{if empty($theme.parents)}
{if $theme.pageType != 'admin'}
<?php @readfile('http://www.mysite.com/gallery2/mediaBlock.php?g2_itemId=33&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');?>
{/if}
{/if}

{assign var="childrenInColumnCount" value=0}

I've tried moving the last {/if} to various places, but have only succeeded in removing the image thumbs from the individual album pages!!! Which was the opposite of what I needed...

Suggestions gratefully received.

Cheers,

Tracy

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Thu, 2009-08-20 13:35

Tracy,
We have not abandoned you and you did not need to start a new thread. You said you did not know this stuff well so we are going in baby steps and are not going to design this custom theme for you but hold your hand in the process so you can learn.

We also have to sleep as well as go to work. I will continue to assist you when I get time; after my real job.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Thu, 2009-08-20 14:05

Hi Floridave,

Sorry, I'm never sure about Forum etiquette so started a new one as it seemed a more general Gallery2 question. Should I delete the other topic? Don't want to irritate you helpful peeps out there.

I'll be working on the site again this evening...I anticipate another sleepless night as I rush to get it finished.

And...yes I really do need my hand held on this. I can cope with hacking Wordpress and Xoops, but this has got me all discombobulated!

Cheers,

Tracy

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Fri, 2009-08-21 00:11

Success! :)

For anyone else out there looking for the solution, you need to edit your album.tpl as follows. The additions are in bold. The 'theme.item.id is the id of your root album:

Quote:
<h3 class="emptyAlbum">
{g->text text="This album is empty."}
{if isset($theme.permissions.core_addDataItem)}
<br/>
<a href="{g->url arg1="view=core.ItemAdmin" arg2="subView=core.ItemAdd"
arg3="itemId=`$theme.item.id`"}">
{g->text text="Add a photo!"}
</a>
{/if}
</h3>
</div>
{else}
{if $theme.item.id == 7}
{php} @readfile('http://www.yoursite.com/gallery2/mediaBlock.php?g2_itemId=7&mode=dynamic&g2_view=dynamicalbum.RandomAlbum&limit=40&useThumb=1&column=4&useMicro=40');{/php}
{else}

{assign var="childrenInColumnCount" value=0}
<div class="gsContentAlbum">
<table id="gsThumbMatrix" width="100%">
<tr valign="top">
{foreach from=$theme.children item=child}

{* Move to a new row *}
{if ($childrenInColumnCount == $theme.params.columns)}
</tr>
<tr valign="top">
{assign var="childrenInColumnCount" value=0}
{/if}

{assign var=childrenInColumnCount value="`$childrenInColumnCount+1`"}
<td class="{if $child.canContainChildren}giAlbumCell{else}giItemCell{/if}"
style="width: {$theme.columnWidthPct}%">
{if ($child.canContainChildren || $child.entityType == 'GalleryLinkItem')}
{assign var=frameType value="albumFrame"}
{capture assign=linkUrl}{g->url arg1="view=core.ShowItem"
arg2="itemId=`$child.id`"}{/capture}
{else}
{assign var=frameType value="itemFrame"}
{capture assign=linkUrl}{strip}
{if $theme.params.dynamicLinks == 'jump'}
{g->url arg1="view=core.ShowItem" arg2="itemId=`$child.id`"}
{else}
{g->url params=$theme.pageUrl arg1="itemId=`$child.id`"}
{/if}
{/strip}{/capture}
{/if}
<div>
{strip}
{if isset($theme.params.$frameType) && isset($child.thumbnail)}
{g->container type="imageframe.ImageFrame" frame=$theme.params.$frameType
width=$child.thumbnail.width height=$child.thumbnail.height}
<a href="{$linkUrl}">
{g->image id="%ID%" item=$child image=$child.thumbnail class="%CLASS% giThumbnail"}
</a>
{/g->container}
{elseif isset($child.thumbnail)}
<a href="{$linkUrl}">
{g->image item=$child image=$child.thumbnail class="giThumbnail"}
</a>
{else}
<a href="{$linkUrl}" class="giMissingThumbnail">
{g->text text="no thumbnail"}
</a>
{/if}
{/strip}
</div>

{g->block type="core.ItemLinks" item=$child links=$child.itemLinks}

{if !empty($child.title)}
{if $child.canContainChildren}
<table cellpadding="0" cellspacing="0">
<tr>
<td class="giTitleIcon">
<img src="{g->url href="themes/euphrosene/images/album.gif"}" alt=""/>
</td>
<td>
<p class="giTitle">{$child.title|markup}</p>
</td>
</tr>
</table>
{else}
<p class="giTitle">{$child.title|markup}</p>
{/if}
{/if}

{if !empty($child.summary)}
<p class="giDescription">
{$child.summary|markup|entitytruncate:256}
</p>
{/if}

{if !$theme.params.itemDetails}
{g->block type="core.ItemInfo"
item=$child
showSummaries=true
class="giInfo"}
{else}
{if ($child.canContainChildren && $theme.params.showAlbumOwner) ||
(!$child.canContainChildren && $theme.params.showImageOwner)}
{assign var="showOwner" value=true}
{else}
{assign var="showOwner" value=false}
{/if}

{/if}
</td>
{/foreach}

{* flush the rest of the row with empty cells *}
{section name="flush" start=$childrenInColumnCount loop=$theme.params.columns}
<td>&nbsp;</td>
{/section}
</tr>
</table>
</div>
{/if}
{/if}
</td>
</tr>
</table>
Apologies for the long piece of code!

Thanks everyone for your help. It's much appreciated.

I may be back...

Cheers,

Tracy

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 22892
Posted: Fri, 2009-08-21 02:13

Glad you got it sorted.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
Freelancealot

Joined: 2009-08-18
Posts: 36
Posted: Fri, 2009-08-21 02:59

Thanks.

See you over at the other thread! :)

Cheers,

Tracy