A UDT for the album module to show a different album per page

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
gap_tooth_clan

A UDT for the album module to show a different album per page

Post by gap_tooth_clan »

Tried to log in to the documentation, was not working and no sign up so I thought I would share this tag here.

I wanted a different album to appear on each page but the module only allows you to supply a list of IDs which is not exactly an elegant solution to the problem. I just created a UDT to look up the id of an album from the page alias.

To make this work your page alias would have to be like: 'gallery-page' and your album name would be 'Gallery Page'

Use this in your template

Code: Select all

{gallery_gen pagetitle=$page_alias}
{if $g_id != 'false'}
{cms_module module='album' albums="$g_id"}
{/if}
To call the UDT called gallery_gen

Code: Select all

global $gCms;

if( !isset($gCms) ) exit;

$db = &$gCms->GetDb();

$pagetitle = ucwords (  str_replace ('-', ' ', $params['pagetitle']) );

$query = 'SELECT album_id FROM cms_module_album_albums WHERE album_name = ? LIMIT 1';

$galleryId = $db->Execute($query, array($pagetitle));


if ($galleryId->RecordCount() == 1) {

  $row = $galleryId->FetchRow();

  $smarty->assign('g_id', $row['album_id']);

  return true;

} else {

  $smarty->assign('g_id', 'false');

  return false;

}	
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: A UDT for the album module to show a different album per page

Post by blast2007 »

Nice work. I suggest only one little mod to your code:
$query = 'SELECT album_id FROM '.cms_db_prefix() . 'cms_module_album_albums WHERE album_name = ? LIMIT 1';
instead of:
$query = 'SELECT album_id FROM cms_module_album_albums WHERE album_name = ? LIMIT 1';
Regards
blast
gap_tooth_clan

Re: A UDT for the album module to show a different album per page

Post by gap_tooth_clan »

I was thinking that as I uploaded it, but feeling very lazy today  :D
Post Reply

Return to “Tips and Tricks”