Jump to content

Go to a random page from a list of 100

Recommended Posts

11 hours ago, simonnowis said:

so in essence, 'buttonBlockId' in the simpler code, is not exactly the same as the 'selector' in the more advanced version?

You can think of a selector kind of like an address. So in this case the block ID got you to the city. The a got you to the street address.

Quote

if i now make changes on the page that has the random button, will this impact the functionality of the code?

It depends on the changes you make but in general if you don't remove the block from the page its ID should not change.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • 1 month later...
1 hour ago, Brycejh said:

What am I missing here?

The poster that I responded to already had jQuery installed so I didn't add that step to my post. I have updated my post with that install step. Do that step and let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
18 hours ago, creedon said:

The poster that I responded to already had jQuery installed so I didn't add that step to my post. I have updated my post with that install step. Do that step and let us know how it goes.

Awesome thank you, I got it to work!

 

Is it possible to have a button that does this for a blog page?  Sqsp seems to give blog pages a random /page url and I was wondering if there was a way to just have it open a random blog page?

 

Thank you

Link to comment

I should clarify maybe what I'm needing to achieve, and hopefully someone can tell me if it's possible.

 

I want users to be able to visit a blog page of mine, click a button and have another random blog page open.  I want users to be able to click "RANDOM" as many times as they would like and always see a random blog post.

The problem that I'm hitting is that the button ID changes every time a new blog post is added.  Would I need to update the button ID for each individual blog post?

 

Thank you

Link to comment
8 hours ago, Brycejh said:

The problem that I'm hitting is that the button ID changes every time a new blog post is added.  Would I need to update the button ID for each individual blog post?

I've made my code more generalized so it may help with the effect you want to achieve.

You can set buttonUrl to something like the following.

    const buttonUrl = '#joke';

Then set the URL for each button you want to randomize to #joke. This helps the code find the button.

Let me know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
14 hours ago, creedon said:

I've made my code more generalized so it may help with the effect you want to achieve.

You can set buttonUrl to something like the following.

    const buttonUrl = '#joke';

Then set the URL for each button you want to randomize to #joke. This helps the code find the button.

Let me know how it goes.

This worked absolutely perfect, thank you so much!

 

I added the code to the site wide code injection area so that it applies to all my blog pages and using the #___ in the button URL saved the day.  Thanks for all your help!

Link to comment
45 minutes ago, terribleadmin said:

Not sure if it's because of using a prefix of '/product/' or something else I'm missing.

It appears you are following instructions for an older version of the code. If you look back in this thread to my Monday post I mention the new format for the buttonUrl setting, it should be the the URL you set your button block URL to.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

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.