Jump to content

Images / Gallery sorting order based on language


sins7ven
 Share

Recommended Posts

Hi Processwire Community,

I am wondering if its possible to change the order of an image gallery based on the language. I have the following use case. A multi-language website (german, english, dutch). These are business websites and they show some clients logos. Now basically this would just be an issue of using the image field and getting all images in one and iterating over them to generate the output. Now how would it be possible to change the order of how they appear based on the language? Let's say for the german site I want some logos to appear much earlier than for example on the dutch site. Is that possible? I found some forum entries about language alternate fields so which would basically mean I need to set up 3 different fields (gallery, gallery_english, gallery_dutch) to make it possible to set different sort orders of the logos? But wouldn't this also mean I basially end up having 3 versions of each logo/image on my page? Or is there another way to achieve this? 

I was also thinking about creating a repeater field for each image so I can add some more properties to each image (e.g. a category so I can later use some Javascript to build some nice category filters). So in regards to my example above I would need 3 different repeater fields (e.g. gallery_repeater, gallery_repeater_english, gallery_repeater_dutch) to get this working, right? How much impact does that have on the performance, assuming I have something between 40 and 50 logos to display (which would basically mean 40-50 repeater items per language). 

Link to comment
Share on other sites

This is really just a quick'n'dirty script, but I guess it should keep you going...

$userlang = $user->language->name;
echo "$userlang <hr>";
$g = $page->gallery->sort('tags'); // all images, sorted by tag (just for debugging)
echo "all: <br>";
foreach($g as $pic) {
    echo "{$pic->tags} {$pic->url}<br>";
}
echo "<hr>";
$g = $page->gallery->find("tags=$userlang"); // only images having current user language tag
echo "userlang: <br>";
foreach($g as $pic) {
    echo "{$pic->tags}  {$pic->url}<br>";
}
$g = $page->gallery->find("tags!=$userlang"); // only images NOT having current user language tag
echo "NOT userlang: <br>";
foreach($g as $pic) {
    echo "{$pic->tags}  {$pic->url}<br>";
}

 

  • Like 1
Link to comment
Share on other sites

Thanks a lot Dragan, but this is something I am already aware of and my problem is a bit different. Please see the image here as an illustration example. It is more a matter of rearranging the order within each language. So when I just sort by the language tag it just outputs all the logos that have this particular language tag but not in a specific order as I would set it in the backend with drag and drop of the gallery items. But I assume this could also be done with some tags. Just creating some tags (first, second, third etc) and assigning them as well to the tags so they would appear before the other ones that do not have one of these "priority" tags? 

logo-order.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...