coppermine-gallery.com/forum

Support => cpg1.4.x Support => Older/other versions => cpg1.4 themes/skins/templates => Topic started by: jay-jay on September 21, 2008, 10:11:46 PM

Title: Grid layout for thumbs on index page
Post by: jay-jay on September 21, 2008, 10:11:46 PM
How to you display category thumbnails on the index page in a grid (say, three thumbs per row) rather than as a single column? This is easy enough to do with the albums page, but not with the main page it seems.
Title: Re: Grid layout for thumbs on index page
Post by: Gizmo on September 22, 2008, 02:23:13 AM
Is this (http://forum.coppermine-gallery.net/index.php/topic,40417.0.html) what you're looking for?
Title: Re: Grid layout for thumbs on index page
Post by: jay-jay on September 22, 2008, 01:20:28 PM
I did read that thread, plus the one it referred to, but couldn't make head or tail from it. My theme.php seems to be set up quite differently:

<?php
define
('THEME_HAS_RATING_GRAPHICS'1);

$template_sys_menu_spacer ='<img src="themes/siteground8/images/line.gif" width="9" height="11" border="0" alt="" />';


function 
theme_display_film_strip(&$thumb_list$nbThumb$album_name$aid$cat$pos$sort_options$mode 'thumb')
{
    global 
$CONFIG$THEME_DIR;
    global 
$template_film_strip$lang_film_strip;

    static 
$template '';
    static 
$thumb_cell '';
    static 
$empty_cell '';
    static 
$spacer '';

    if ((!
$template)) {
        
$template $template_film_strip;
        
$thumb_cell template_extract_block($template'thumb_cell');
        
$empty_cell template_extract_block($template'empty_cell');
    }

    
$cat_link is_numeric($aid) ? '' '&amp;cat=' $cat;

    
$thumbcols $CONFIG['thumbcols'];
    
$cell_width ceil(100 $CONFIG['max_film_strip_items']) . '%';

    
$i 0;
    
$thumb_strip '';
    foreach(
$thumb_list as $thumb) {

        
$new_size 65;
        
preg_match('/(?<=width=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcWidth=$matches[0][0];
        
preg_match('/(?<=height=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcHeight=$matches[0][0];
        
$ratio max($srcWidth$srcHeight) / $new_size;
        
$ratio max($ratio1.0);
        
$destWidth = (int)($srcWidth $ratio);
        
$destHeight = (int)($srcHeight $ratio);
        
$thumb['image']=preg_replace('/width="[^"]*"/','width="'.$destWidth.'"',$thumb['image']);
        
$thumb['image']=preg_replace('/height="[^"]*"/','height="'.$destHeight.'"',$thumb['image']);
        
$i++;
        if (
$mode == 'thumb') {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos={$thumb['pos']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => $thumb['caption'],
                
'{ADMIN_MENU}' => ''
                
);
        } else {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "index.php?cat={$thumb['cat']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => '',
                
'{ADMIN_MENU}' => ''
                
);
        }
        
$thumb_strip .= template_eval($thumb_cell$params);
    }

    if (
defined('THEME_HAS_FILM_STRIP_GRAPHICS')) {
        
$tile1 $THEME_DIR 'images/tile1.gif';
        
$tile2 $THEME_DIR 'images/tile2.gif';
    } elseif (
defined('THEME_HAS_FILM_STRIP_GRAPHIC')) {
        
$tile1=$tile2=$THEME_DIR 'images/tile.gif';
    } else {
        
$tile1=$tile2'images/tile.gif';
    }

    
$params = array('{THUMB_STRIP}' => $thumb_strip,
        
'{COLS}' => $i,
        
'{TILE1}' => $tile1,
        
'{TILE2}' => $tile2,
        );

    
ob_start();
    
starttable($CONFIG['picture_table_width']);
    echo 
template_eval($template$params);
    
endtable();
    
$film_strip ob_get_contents();
    
ob_end_clean();

    return 
$film_strip;
}
?>



I'm not a php wiz, so any help would be appreciated.
Title: Re: Grid layout for thumbs on index page
Post by: Gizmo on September 23, 2008, 01:08:20 PM
There are several lessons to be learned here.


I copied and pasted the copy that appeared at the end of the above topic (by Marius) into theme.php and it worked for the classic theme. I then hunted down your theme (siteground8 (http://www.siteground.com/templates_list.php)) to try it with that theme. It worked as well BUT because of styling differences, the category description and stats wouldn't show (hence the need for a link to your gallery or theme). This has to be dealt with by changing the styling in the style.css file.

The new theme.php file:

<?php
define
('THEME_HAS_RATING_GRAPHICS'1);

$template_sys_menu_spacer ='<img src="themes/siteground8/images/line.gif" width="9" height="11" border="0" alt="" />';

// HTML template for the category list
$template_cat_list = <<<EOT
<!-- BEGIN header -->
        <tr>
                <td class="tableh1" align="left"><b>{CATEGORY}</b></td>
      </tr>
      <tr>
      <td>
        <div class="categories">
<!-- END header -->
<!-- BEGIN catrow_noalb -->
        <div class="catcell">
                {CAT_THUMB}<br /><span class="catlink">{CAT_TITLE}</span><br />{CAT_DESC}<br />{PIC_COUNT} photos in {ALB_COUNT} albums
        </div>
<!-- END catrow_noalb -->
<!-- BEGIN catrow -->
        <div class="catcell">
                <div style="float: left; width: 24%; text-align: center;">
            {CAT_THUMB}
            </div>
            <div style="float: right; width: 74%;">
            <span class="catlink">{CAT_TITLE}</span><br /><span class="thumb_caption">{CAT_DESC}<br />{PIC_COUNT} wallpapers in {ALB_COUNT} albums</span></div>
            <div style="clear: both;"></div>
        </div>
<!-- END catrow -->
<!-- BEGIN footer -->
      </div>
      </td>
      </tr>
        <tr>
                <td colspan="3" class="tableh1" align="center"><span class="statlink">{STATISTICS}</span></td>
        </tr>
<!-- END footer -->
<!-- BEGIN spacer -->
        <img src="images/spacer.gif" width="1" height="7" border="" alt="" /><br />
<!-- END spacer -->

EOT;

function 
theme_display_film_strip(&$thumb_list$nbThumb$album_name$aid$cat$pos$sort_options$mode 'thumb')
{
    global 
$CONFIG$THEME_DIR;
    global 
$template_film_strip$lang_film_strip;

    static 
$template '';
    static 
$thumb_cell '';
    static 
$empty_cell '';
    static 
$spacer '';

    if ((!
$template)) {
        
$template $template_film_strip;
        
$thumb_cell template_extract_block($template'thumb_cell');
        
$empty_cell template_extract_block($template'empty_cell');
    }

    
$cat_link is_numeric($aid) ? '' '&amp;cat=' $cat;

    
$thumbcols $CONFIG['thumbcols'];
    
$cell_width ceil(100 $CONFIG['max_film_strip_items']) . '%';

    
$i 0;
    
$thumb_strip '';
    foreach(
$thumb_list as $thumb) {

        
$new_size 65;
        
preg_match('/(?<=width=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcWidth=$matches[0][0];
        
preg_match('/(?<=height=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcHeight=$matches[0][0];
        
$ratio max($srcWidth$srcHeight) / $new_size;
        
$ratio max($ratio1.0);
        
$destWidth = (int)($srcWidth $ratio);
        
$destHeight = (int)($srcHeight $ratio);
        
$thumb['image']=preg_replace('/width="[^"]*"/','width="'.$destWidth.'"',$thumb['image']);
        
$thumb['image']=preg_replace('/height="[^"]*"/','height="'.$destHeight.'"',$thumb['image']);
        
$i++;
        if (
$mode == 'thumb') {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos={$thumb['pos']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => $thumb['caption'],
                
'{ADMIN_MENU}' => ''
                
);
        } else {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "index.php?cat={$thumb['cat']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => '',
                
'{ADMIN_MENU}' => ''
                
);
        }
        
$thumb_strip .= template_eval($thumb_cell$params);
    }

    if (
defined('THEME_HAS_FILM_STRIP_GRAPHICS')) {
        
$tile1 $THEME_DIR 'images/tile1.gif';
        
$tile2 $THEME_DIR 'images/tile2.gif';
    } elseif (
defined('THEME_HAS_FILM_STRIP_GRAPHIC')) {
        
$tile1=$tile2=$THEME_DIR 'images/tile.gif';
    } else {
        
$tile1=$tile2'images/tile.gif';
    }

    
$params = array('{THUMB_STRIP}' => $thumb_strip,
        
'{COLS}' => $i,
        
'{TILE1}' => $tile1,
        
'{TILE2}' => $tile2,
        );

    
ob_start();
    
starttable($CONFIG['picture_table_width']);
    echo 
template_eval($template$params);
    
endtable();
    
$film_strip ob_get_contents();
    
ob_end_clean();

    return 
$film_strip;
}
?>



Add this to your style.css file:

.catcell {
   float: left;
   width: 32%;
   text-align: left;
   margin: 5px auto;
   padding-left: 5px;
}


Edit the color for .thumb_caption in the style.css file:

.thumb_caption {
color: #fefefe;
display: block;
font-size: 85%;
padding: 1px;
}


This code change doesn't take into account empty categories which throws up an error. There are other items that may need some attention so I'll leave those to you.
Title: Re: Grid layout for thumbs on index page
Post by: jay-jay on September 23, 2008, 09:37:08 PM
Thanks Gizmo - much appreciated. Sorry for not providing the link. Here it is: http://xn--vtr-x0a6588a.com (http://xn--vtr-x0a6588a.com).

This is looking pretty much looking as I want it to (I removed the album stats as a matter of personal preference). I increased the category title to 100%, but it still looks rather small and would probably be better placed above the thumbnails to increase its prominence (I'll have a hunt around on the forum to see if there is a thread that addresses the placement of category titles).

I guess the more immediate concern is that the thumbnails are not fully aligned. Do you know what might be causing this?
Title: Re: Grid layout for thumbs on index page
Post by: Gizmo on September 23, 2008, 09:46:19 PM
You removed the album stats but you didn't remove the container they were in. You need to also remove that to get the pics to be centered and you don't need the spacer.


<td>
<img width="1" height="1" border="0" alt="" src="images/spacer.gif"/>
</td>
<td class="tableb_compact" width="100%" valign="top" align="left">
<p/>
<p class="album_stat"/>
</td>
Title: Re: Grid layout for thumbs on index page
Post by: jay-jay on September 24, 2008, 02:39:04 PM
Okay, but where do I find that block of code? It's not in my theme.php file.
Title: Re: Grid layout for thumbs on index page
Post by: Gizmo on September 25, 2008, 01:15:50 PM
Replace the below code with what's currently in your theme.php file.

<?php
define
('THEME_HAS_RATING_GRAPHICS'1);

$template_sys_menu_spacer ='<img src="themes/siteground8/images/line.gif" width="9" height="11" border="0" alt="" />';

// HTML template for the category list
$template_cat_list = <<<EOT
<!-- BEGIN header -->
        <tr>
                <td class="tableh1" align="left"><b>{CATEGORY}</b></td>
      </tr>
      <tr>
      <td>
        <div class="categories">
<!-- END header -->
<!-- BEGIN catrow_noalb -->
        <div class="catcell">
                {CAT_THUMB}<br /><span class="catlink">{CAT_TITLE}</span><br />{CAT_DESC}<br />{PIC_COUNT} photos in {ALB_COUNT} albums
        </div>
<!-- END catrow_noalb -->
<!-- BEGIN catrow -->
        <div class="catcell">
                <div style="float: left; width: 24%; text-align: center;">
            {CAT_THUMB}
            </div>
            <div style="float: right; width: 74%;">
            <span class="catlink">{CAT_TITLE}</span><br /><span class="thumb_caption">{CAT_DESC}<br />{PIC_COUNT} wallpapers in {ALB_COUNT} albums</span></div>
            <div style="clear: both;"></div>
        </div>
<!-- END catrow -->
<!-- BEGIN footer -->
      </div>
      </td>
      </tr>
        <tr>
                <td colspan="3" class="tableh1" align="center"><span class="statlink">{STATISTICS}</span></td>
        </tr>
<!-- END footer -->
<!-- BEGIN spacer -->
        <img src="images/spacer.gif" width="1" height="7" border="" alt="" /><br />
<!-- END spacer -->

EOT;

// HTML template for the album list
$template_album_list = <<<EOT

<!-- BEGIN stat_row -->
        <tr>
                <td colspan="{COLUMNS}" class="tableh1" align="center"><span class="statlink">{STATISTICS}</span></td>
        </tr>
<!-- END stat_row -->
<!-- BEGIN header -->
        <tr class="tableb_compact">
<!-- END header -->
<!-- BEGIN album_cell -->
        <td width="{COL_WIDTH}%" valign="top">
        <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
                <td colspan="3" height="1" align="left" valign="top" class="tableh2">
                        <span class="alblink"><a href="{ALB_LINK_TGT}"><b>{ALBUM_TITLE}</b></a></span>
                </td>
        </tr>
        <tr>
                <td colspan="3">
                        <img src="images/spacer.gif" width="1" height="1" border="0" alt="" /><br />
                </td>
        </tr>
        <tr>
                <td align="center" valign="middle" class="thumbnails">
                        <img src="images/spacer.gif" width="{THUMB_CELL_WIDTH}" height="1" class="image" style="margin-top: 0px; margin-bottom: 0px; border: none;" alt="" /><br />
                        <a href="{ALB_LINK_TGT}" class="albums">{ALB_LINK_PIC}<br /></a>
{ADMIN_MENU}
                </td>
        </tr>
        </table>
        </td>
<!-- END album_cell -->
<!-- BEGIN empty_cell -->
        <td width="{COL_WIDTH}%" valign="top">
        <table width="100%" cellspacing="0" cellpadding="0">
        <tr>
                <td height="1" valign="top" class="tableh2">
                        <b>&nbsp;</b>
                </td>
        </tr>
        <tr>
                <td>
                        <img src="images/spacer.gif" width="1" height="1" border="0" alt="" /><br />
                </td>
        </tr>
        <tr>
                <td width="100%" valign="top" class="tableb_compact">
                    <div class="thumbnails" style="background-color:transparent"><img src="images/spacer.gif" width="1" height="1" border="0" class="image" style="border:0;margin-top:1px;margin-bottom:0" alt="" /></div>
                </td>
        </tr>
        </table>
        </td>
<!-- END empty_cell -->
<!-- BEGIN row_separator -->
        </tr>
        <tr class="tableb_compact">
<!-- END row_separator -->
<!-- BEGIN footer -->
        </tr>
<!-- END footer -->
<!-- BEGIN tabs -->
        <tr>
                <td colspan="{COLUMNS}" style="padding: 0px;">
                        <table width="100%" cellspacing="0" cellpadding="0">
                                <tr>
                                       {TABS}
                                </tr>
                        </table>
                </td>
        </tr>
<!-- END tabs -->
<!-- BEGIN spacer -->
        <img src="images/spacer.gif" width="1" height="7" border="" alt="" /><br />
<!-- END spacer -->

EOT;

function 
theme_display_film_strip(&$thumb_list$nbThumb$album_name$aid$cat$pos$sort_options$mode 'thumb')
{
    global 
$CONFIG$THEME_DIR;
    global 
$template_film_strip$lang_film_strip;

    static 
$template '';
    static 
$thumb_cell '';
    static 
$empty_cell '';
    static 
$spacer '';

    if ((!
$template)) {
        
$template $template_film_strip;
        
$thumb_cell template_extract_block($template'thumb_cell');
        
$empty_cell template_extract_block($template'empty_cell');
    }

    
$cat_link is_numeric($aid) ? '' '&amp;cat=' $cat;

    
$thumbcols $CONFIG['thumbcols'];
    
$cell_width ceil(100 $CONFIG['max_film_strip_items']) . '%';

    
$i 0;
    
$thumb_strip '';
    foreach(
$thumb_list as $thumb) {

        
$new_size 65;
        
preg_match('/(?<=width=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcWidth=$matches[0][0];
        
preg_match('/(?<=height=")[0-9]*/',$thumb['image'],$matches,PREG_OFFSET_CAPTURE);
        
$srcHeight=$matches[0][0];
        
$ratio max($srcWidth$srcHeight) / $new_size;
        
$ratio max($ratio1.0);
        
$destWidth = (int)($srcWidth $ratio);
        
$destHeight = (int)($srcHeight $ratio);
        
$thumb['image']=preg_replace('/width="[^"]*"/','width="'.$destWidth.'"',$thumb['image']);
        
$thumb['image']=preg_replace('/height="[^"]*"/','height="'.$destHeight.'"',$thumb['image']);
        
$i++;
        if (
$mode == 'thumb') {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "displayimage.php?album=$aid$cat_link&amp;pos={$thumb['pos']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => $thumb['caption'],
                
'{ADMIN_MENU}' => ''
                
);
        } else {
            
$params = array('{CELL_WIDTH}' => $cell_width,
                
'{LINK_TGT}' => "index.php?cat={$thumb['cat']}",
                
'{THUMB}' => $thumb['image'],
                
'{CAPTION}' => '',
                
'{ADMIN_MENU}' => ''
                
);
        }
        
$thumb_strip .= template_eval($thumb_cell$params);
    }

    if (
defined('THEME_HAS_FILM_STRIP_GRAPHICS')) {
        
$tile1 $THEME_DIR 'images/tile1.gif';
        
$tile2 $THEME_DIR 'images/tile2.gif';
    } elseif (
defined('THEME_HAS_FILM_STRIP_GRAPHIC')) {
        
$tile1=$tile2=$THEME_DIR 'images/tile.gif';
    } else {
        
$tile1=$tile2'images/tile.gif';
    }

    
$params = array('{THUMB_STRIP}' => $thumb_strip,
        
'{COLS}' => $i,
        
'{TILE1}' => $tile1,
        
'{TILE2}' => $tile2,
        );

    
ob_start();
    
starttable($CONFIG['picture_table_width']);
    echo 
template_eval($template$params);
    
endtable();
    
$film_strip ob_get_contents();
    
ob_end_clean();

    return 
$film_strip;
}
?>



Have a look at the theme creating section (http://coppermine-gallery.net/demo/cpg14x/docs/index.htm#creating) of the manual and the stickies above to learn how this is done. Check out this post (http://forum.coppermine-gallery.net/index.php/topic,31423.0.html) to get some tools to make this easier for you.
Title: Re: Grid layout for thumbs on index page
Post by: jay-jay on September 25, 2008, 04:22:33 PM
Thanks Gizmo. The new code works a treat! I still have to sort out the size and positioning of the album titles, so I'll have a look through the forum posts to see if there is a solution (perhaps one of those tools listed in the link you provided might help?) and have a go at fiddling with the code (baby steps towards learning about php coding!). If I get stuck I'll post in a new thread. Thanks for your help!