Hello EE gang,
I just created a working picture gallery using weblogs / FF matrix / ngen file field and was wondering if I am doing everything ok or if there is a way to optimise the code.
The main setup of the gallery goes as follow:
* FF Matrix with 3 columns: gnen file field for pictures / description text / copyright text
* The imgsizer plugin is used to create the thumbnails
Here is the code in my detail template
<?php
global $IN;
if ($IN->fetch_uri_segment('4') != "")
{
$activepicture = $IN->fetch_uri_segment('4');
}
else
{
$activepicture = 1;
}
?>
{exp:weblog:entries weblog="picture_galleries" limit="1" disable="categories|category_fields|member_data|pagination|trackbacks"}
{pictgallery_pictures}
{if ({row_count} == <?php echo $activepicture; ?>)}
<p>{exp:imgsizer:size src="{picture}" width="400" alt=""}</p>
<p>{legend}</p>
<p>© {copyright}</p>
{if (<?php echo $activepicture; ?> > 1)}
<p><a href="{path='picture_galleries/detail/{url_title}/<?php echo ($activepicture-1) ?>'}">Previous</a></p>
{/if}
{if (<?php echo $activepicture; ?> < {total_rows})}
<p><a href="{path='picture_galleries/detail/{url_title}/<?php echo ($activepicture+1) ?>'}">Next</a></p>
{/if}
{/if}
{/pictgallery_pictures}
{/exp:weblog:entries}
{exp:weblog:entries weblog="picture_galleries" limit="1" disable="categories|category_fields|member_data|pagination|trackbacks"}
{title}
<ul>
{pictgallery_pictures}
<li>
<p><a href="{path='picture_galleries/detail/{url_title}/{row_count}'}">{exp:imgsizer:size src="{picture}" width="80" alt=""}</a></p>
</li>
{/pictgallery_pictures}
</ul>
{/exp:weblog:entries}
step one
————
The second weblog entries loops through all the pictures in the FF matrix field {pictgallery_pictures} and displays thumbnails of pictures. Links on each picture link to the same template + appends the row_count parameter to the url.
step two
————
The PHP bit (parse on input) checks if there is a segment_4 in the URL (the row_count parameter just passed via the URL). If there is one, its value is given to the php variable $activepicture. If not, $activepicture value’s is set to 1.
step three
—————
The first weblog entries displays the active picture in a larger format. It does so by looping through all the pictures in the gallery and comparing their row_count value to the value stored in the $activepicture variable. If they match, the picture is displayed. Otherwise, nothing is displayed.
EDIT: added “next” and “previous” links
Voilà. Works perfectly in my local dev machine but I wonder if there is not a way to optimize the code further. Any idea ?
