Jump to content
garywhitling

Gallery Image Ordering

Recommended Posts

Hi,

I was wondering if anyone is aware of how to arrange the images within the gallery area on the product page in to a certain order.  For example drag and drop in to position from within the admin area or alphabetically within the code.

 

Share this post


Link to post
Share on other sites

Not drag-n-drop, but we can make a small edit to the database query that gets all the assigned images for a given product so that the non-main images get sorted by the filename.

In /classes/catalogue .class.php, near the bottom:

Find the private function _productGallery(), then find the statement:

Starts with:

if (($gallery = $GLOBALS['db']->select

Change the end of that line, from:

'ORDER BY i.main_img DESC'))) {

To be:

'ORDER BY i.main_img DESC, filename ASC'))) {

This edit will not survive an upgrade, but there is a hook we can use to resort the $return variable.

Share this post


Link to post
Share on other sites

Hi Brian,

Great stuff I have just made the changes you mentioned and that helps for now :-)

Ideally we would like to set the order of the images differently depending on the product page. otherwise we will have to re-name images to get them in-line.

Are you aware of any mods/plugins that offer this?

Regards Gary

Share this post


Link to post
Share on other sites

I can envision the jQuery plugin FileTree acquiring the ability to have an arbitrary sort. I think that would be the only way.

Share this post


Link to post
Share on other sites

https://www.cubecart.com/extensions/plugins/product-image-rollover this plugin has that feature as an extra to the “main” functionality which is adding image rollover (auto-switching between two designated images when the mouse hovers over the image).  Much more control over the order of the images AND no code edits to core CubeCart

Ian

Share this post


Link to post
Share on other sites

I think I found a solution, even if it's a bit cumbersome.  Before you begin, have a list of the images you want for your product in the order you want them to appear. For example: 

  1. Image 1 (primary image)
  2. Image 2
  3. Image 3
  4. Image 4

Go to your product page and then to the image tab.

Remove all of your images (except the image you want to be starred for the primary image) from the product. Click "Save and Reload"

Then, look at your list, and going in REVERSE order (begin with the image you want to appear last), click the checkbox of the image that is last on your list (In the example, this would be Image 4).

Click "Save and Reload". This will add the image to top of the list, but after the primary image.

Then add the next to last image (Image 3, in the example). Click "Save and Reload" to add the image to the top of the list, but after the primary image.

Keep doing this until you have added all of the images (all the way to Image 2)

 

As I said, cumbersome, but you can do it in the product page of the admin console.

 

Share this post


Link to post
Share on other sites

Hi Dnhart29,

Thank you for the suggestion, unfortunately I have over 2,700 products with roughly 7 images each :-(

So I am looking for an automated option. I am nearly there with a mod from Havenswift so keeping my fingers crossed with that

But thanks for having a look and spending the time to reply

Regards Gary

Share this post


Link to post
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

×