Announcement

  •  » Extensions
  •  » show more thumbnails per album on albums list page

#1 2016-06-22 22:33:21

Ninjay
Member
2016-06-22
2

show more thumbnails per album on albums list page

Sup

What I'd like to achieve is to show more thumbnails per album (on frontpage's albums list).
Currently album box contains 1 thumbnail, album name, description, author etc.
I'd like to set 3-5 thumbs in such box on list of albums.

Is there any way to achieve this ?

I've found a 4 years old similar thread, but I'm not 100% sure if OP asked for same thing:
http://piwigo.org/forum/viewtopic.php?id=20006
Since its old enough I thought I'll ask again.

I've seen such solution on http://fotopozytywy.pl galleries, but those aren't based on piwigo :(

--
Using latest pig 2.8.1

Offline

 

#2 2016-06-23 09:12:42

teekay
Member
2013-06-12
427

Re: show more thumbnails per album on albums list page

In the thread you linked to, OP asked if it's possible to modify the number of colums per row on the album preview (thumbnails page). If I got you right, you want x thumbnails per album on the category page.

I don't think there is a simple native method or any theme that does this already, but everything is possible :)

My first idea would be to override the mainpage_categories.tpl template to simply provide a skeleton HTML structure, and then fill it using jQuery via the Piwigo Webservice API by retrieving the category list and the last x images per category.

Last edited by teekay (2016-06-23 09:13:09)

Offline

 

#3 2016-06-23 10:28:59

teekay
Member
2013-06-12
427

Re: show more thumbnails per album on albums list page

Here is an example of what I'm talking about using the AdditionalPages plugin:
https://pwgdemo.kuther.net/index/page/category_list

Disclaimer: This might not be the best solution, because
a) it will perform badly on huge galleries with hundrets of categories due to client-side javascript code, no pagination yet, etc..
b) nested sub-categories would require more work (the example uses a flat, recursive view with all categories and sub-categories on one page)

So, for a rather small gallery this could do it, anything else requires more work and maybe writing a custom plugin that handles this using PHP on the server-side. :)

The code in AdditionalPages:

Code:

<style type="text/css">
.thumbnail {
  float: left;
  margin-right: 10px;
}
</style>

<div id="categories">
</div>

<script type="text/javascript">
var pwg_api = "/ws.php?format=json";
$.getJSON(pwg_api + '&method=pwg.categories.getList&recursive=true', function (json) {
    categories = json.result.categories;
    $.each( categories, function ( i, cat ) {
       $('#categories').append('<div id="cat-' + cat.id + '" class="row"><h3><a href="' + cat.url + '">' + cat.name + '</a></div>');
       $.getJSON(pwg_api + '&method=pwg.categories.getImages&per_page=5&recursive=true&order=date_available%20desc&cat_id=' + cat.id, function (json) {
          var images = json.result.images;
          $.each( images, function ( i, image ) {
              var src = image.derivatives.square.url;
              var name = image.file;
              var url = image.categories[0].page_url;
              $('#cat-' + cat.id).append('<a href="' + url + '"><img class="thumbnail" src="' + src + '" alt="' + name + '"></a>');
          });
       });
    });
});
</script>

Last edited by teekay (2016-06-23 11:56:34)

Offline

 

#4 2016-06-23 18:17:06

Ninjay
Member
2016-06-22
2

Re: show more thumbnails per album on albums list page

teekay wrote:

If I got you right, you want x thumbnails per album on the category page.

I don't think there is a simple native method or any theme that does this already, but everything is possible :)

My first idea would be to override the mainpage_categories.tpl template to simply provide a skeleton HTML structure, and then fill it using jQuery via the Piwigo Webservice API by retrieving the category list and the last x images per category.

You got me right :)

I thought it won't be too simple, as I haven't found any tip nor plugin which could become a solid base.
But also hoped it wouldn't be that hard.
I had a rendez vois with mainpage_categories.tpl as you suggested. I hoped I will find there a loop with thumbs I could mess with. Unfortunately I'm not familiar with smarty tpl engine, but I understood that also thumbnails.tpl would need to be changed.

I thought about getting thumbs solely from database using php in a raw, hardcore way and putting it inside mainpage.tpl to see if it's possible, and won't break too much things ;) But later I'd need to get familiar with pig's plugin system, vars, then refactor all the raw code, and so on. So getting such feature for non programmer (I just code ... a bit) as a plugin would become a pain.

Code you provided seems to work very nice on page you provided. Big thanx for proof of concept ;)
Unfortunately I don't know the amount of galleries in future, and gallery I'm working on is adaptive to mobile devices, thus it would really need pagination.


K, let's say there's not a native way, no plugin nor raw smarty code droplet that would lead to get more thumbs without complicating things at this time.

Offline

 

#5 2016-06-24 22:24:49

teekay
Member
2013-06-12
427

Re: show more thumbnails per album on albums list page

Well, it shouldn't be too hard.

Create a child theme as described here: http://piwigo.org/doc/doku.php?id=dev:e … e_creation

In the themeconfig.inc.php add a function that pulls the latest x images for a given category from the database. Something like this should work:

Code:

function getCategoryThumbs($cat, $count = 5) {
  $query = '
  SELECT *
    FROM '.IMAGES_TABLE.'
    WHERE id IN (SELECT image_id
                 FROM '.IMAGE_CATEGORY_TABLE.'
                 WHERE category_id = '.$cat.')
    ORDER BY date_available DESC
    LIMIT '.$count.'
  ;';

  $result = pwg_query($query);

  $thumbs = array();
  while ($row = pwg_db_fetch_assoc($result))
  {
    $thumbs[] = $row;
  }

  $tpl_thumbs_var = array();

  foreach ($thumbs as $row)
  {
    $url = duplicate_picture_url(
      array(
        'image_id' => $row['id'],
        'image_file' => $row['file'],
        ),
      array('start')
      );
    $name = render_element_name($row);
    $desc = render_element_description($row, 'main_page_element_description');

    $tpl_var = array_merge( $row, array(
      'NAME' => $name,
      'TN_ALT' => htmlspecialchars(strip_tags($name)),
      'URL' => $url,
      'DESCRIPTION' => $desc,
      'src_image' => new SrcImage($row),
      ));

    $tpl_thumbs_var = $tpl_var;
  }

  return $tpl_thumbs_var;
}

Then copy the parent theme's mainpage_categories.tpl to your child theme folder's template/ subdir.

In the {foreach from=$category_thumbnails item=cat ..} loop get the resulting array from the function, like
{assign var=cat_thumbs value=getCategoryThumbs($cat.id)}, loop over the $cat_thumbs array (there are some examples for creating derivative params in there already), create your HTML structure, etc.

Finally, add a theme.css, too, if required.

Last edited by teekay (2016-06-24 22:31:10)

Offline

 
  •  » Extensions
  •  » show more thumbnails per album on albums list page

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact