x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

Gallery Category Images

Question:

In the Image Gallery, how can I show a list of categories with a random image from each category?

Answer:

It’s not possible with EE tags at the moment, but here are some queries to get you going:

<!--This code is commented out with html comments for your convenience.
They won't affect your template, but feel free to delete them if you want. -->


<!--The following query tag gets the cat_id tag from the database.
It also orders the categories by name (alphabetizes them). Be sure you
change the '
gallery_id' to the ID of your gallery. Everything else should
stay the same -->

{exp:query sql="SELECT cat_id FROM exp_gallery_categories WHERE gallery_id= '
1'
ORDER BY cat_name;"}


<!--This is the opening tag for your category list. The '
{cat_id}' is what
is called from the above query. '
columns="1"' and 'rows="1"' tells it that
we only want one image from each category. '
orderby="random"' tells it to
show a random image from that category. You can order by other things too
(look at http://www.pmachine.com/expressionengine/docs/modules/image_gallery/
gallery_entries.html for examples). Don'
t forget! Replace the "gat_gallery"
name to your gallery's name in between the quotes or this won't work.-->

{exp:gallery:entries gallery="gat_gallery" category="{cat_id}" columns="1"
rows="1" orderby="random"}


<!--These tags are fine as they are. Be sure to keep them-->

{entries}{row}


<!--This is the image tag. Be sure to edit the link appropriately.-->

<
a href="http://yourwebsite.com/index.php/galleryname/category/C{cat_id}">
<
img src="{thumb_url}" width="{thumb_width}" height="{thumb_height}" border="0"
title="{category}" alt="{category}" /></a>

<
br />


<!--
This is a Text link to the category. Again, make sure you change the link.-->
<
a href="http://yourwebsite.com/index.php/galleryname/category/C{cat_id}">
{category}</a>


<!--
These tags are fine as they are. Be sure to keep them-->

{/row}{/entries}

{
/exp:gallery:entries}{/exp:query}


<!--That's it. If you have any questions/problems, feel free to e-mail me at
johnathan@airbrushguy.com-->

<!--You can see a working example at http://grabatag.com. It is on the front
page and also on the '
shop online' page.-->

Category:Tricks Category:Image Gallery

Categories: