Sub-albums...

nickctn

Joined: 2005-01-29
Posts: 15
Posted: Sun, 2005-09-18 09:36

Hi,

I'm trying to customize my own theme, and I would like to know if there was a way to determine if an album only contained sub-albums.

Thanks

Nicolas

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Sun, 2005-09-18 13:57

Yes there is, two ways, I'll show the easier (template-smarty) approach:

Add this in your album.tpl file:

{assign var="hasDataItems" value=0}
{foreach from=$theme.children item=child}
    {if !$child.canContainChildren}
        {assign var="hasDataItems" value=1}
    {/if}
{/foreach}
{if ($hasDataItems == 1)}
    Has data items
{else}
    Has only albums
{/if}

When an album only has albums it will show "Has only albums". Instead of that text you can add any templat code you want...

[edit]When there are 0 subitems (either labums or dataitems) the text will still say "Has only albums" even though there are none. You can use $theme.childCount to test if there are any child items at all.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-09-18 13:58

in theme.inc in showAlbumPage(), you have to do something like:

$theme['hasOnlySubAlbums'] = true;
$theme['subalbums'] = array();
foreach ($theme['children'] as $child) {
    if (isset($child['canContainChildren'] && $child['canContainChildren']) {
        $theme['subalbums'][] = $child;
    } else {
        $theme['hasOnlySubAlbums'] = false;
    }
}
}

then in the templates (album.tpl), use {if $theme.hasOnlySubAlbums} or something like that.

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Sun, 2005-09-18 14:05

Valiants approach is the other one I had in mind :P

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2005-09-18 14:10

hey RwD, thanks for all the support here in the forums! :)
Feel free to add howto's or links on the user contributions page in the codex anytime. then you can just link to the codex instead of writing stuff multiple times.

thanks again for your effort!

 
nickctn

Joined: 2005-01-29
Posts: 15
Posted: Sun, 2005-09-18 16:48

thanks a lot

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Sun, 2005-09-18 17:45
 
joe7rocks
joe7rocks's picture

Joined: 2004-10-07
Posts: 560
Posted: Thu, 2006-03-02 12:54

and how to check if the subalbums of the current album has any child or not? :)
(eg. to hide emtpy subalbums)

 
RwD
RwD's picture

Joined: 2005-01-09
Posts: 383
Posted: Fri, 2006-03-03 09:52
joe7rocks wrote:
and how to check if the subalbums of the current album has any child or not? :)
(eg. to hide emtpy subalbums)

Not quite sure. But I do know how to check for subalbums inside the templates.

{foreach from=$theme.children item=child}
    {if empty($theme.tree[$child.id])}
        {$child.title} has no subalbums
    {else}
        {$child.title} does have subalbums
    {/if}
{/foreach}

I do not think this specific piece of code can be expanded to include checking for dataitems and linkitems. But I do think it is a start ;)