Jump to content

Randomize Specific Portfolio

Recommended Posts

Hello!

I know there's code to randomize your homepage gallery showing your portfolio work, but is it possible to randomize one single portfolio page's gallery when on that specific page?

For example, in the link below, I'd like these images to be randomized each time the page is loaded. However, I don't want that to occur on other portfolio pages where I have things in a specific order.

Is that even possible?

https://www.brettlair.ca/work/logos

Edited by brettlair
Updated "portfolio" to "gallery" in the first sentence to be more accurate.
Link to comment
19 hours ago, brettlair said:

Hello!

I know there's code to randomize your homepage gallery showing your portfolio work, but is it possible to randomize one single portfolio page's gallery when on that specific page?

For example, in the link below, I'd like these images to be randomized each time the page is loaded. However, I don't want that to occur on other portfolio pages where I have things in a specific order.

Is that even possible?

https://www.brettlair.ca/work/logos

You can insert the code to a code block of the page, so it will affect that page only

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - Lightbox captions only mode)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 No-code customisations for Squarespace
🚀 Learn how to rank new pages on Google in 48 hours!

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

Link to comment
  • 2 weeks later...
On 9/11/2024 at 9:37 PM, brettlair said:

Unfortunately I can't do that directly though because the page falls under the "Work" section in the nav which is a Portfolio layout.

I can get it to randomize my homepage gallery no problem, but that's not what I want to do.

Screenshot 2024-09-11 at 11.36.21 AM.png

Okay, then you can identify the page ID, which is unique for every page, then it will only work for the specific porfolio page

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - Lightbox captions only mode)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 No-code customisations for Squarespace
🚀 Learn how to rank new pages on Google in 48 hours!

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

Link to comment

This is the code that will randomize everything on my homepage. I'm not entirely sure how/where to add the specific page ID though.

 

Quote
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('div#gridThumbs');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

Link to comment
On 9/25/2024 at 7:05 PM, brettlair said:

This is the code that will randomize everything on my homepage. I'm not entirely sure how/where to add the specific page ID though.

 

 

Suppose your Portfolio Page ID is: #collection-66a1bfc99041e47b896c1e48

image.png.84c14937f8a5e16913bd17365e3882d3.png

Change your code to this

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('#collection-66a1bfc99041e47b896c1e48 div#gridThumbs');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
On 9/27/2024 at 11:17 PM, tuanphan said:

Suppose your Portfolio Page ID is: #collection-66a1bfc99041e47b896c1e48

image.png.84c14937f8a5e16913bd17365e3882d3.png

Change your code to this

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('#collection-66a1bfc99041e47b896c1e48 div#gridThumbs');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

I only have "item" and "section on this page instead of "collection". Wondering if that's because it's a "Portfolio" category page?

Screenshot 2024-09-30 at 10.07.46 AM.png

Link to comment

Create an account or sign in to comment

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

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.