Jump to content

Blog taglcoud - way to indicate which tag user is currently viewing?

Recommended Posts

4 hours ago, hellomw said:

Site URL: https://www.no-frames.com/photo-test

Hi, 

I am using the tagcoud filter block and would like to be able to indicate what tag has been clicked on/currently viewing. Is this possible?

Add this to code injection - Footer

<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = location.pathname;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
      selectTag.style.fontWeight = "bold";
    }
  }
})()
</script>

 

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

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
11 hours ago, bangank36 said:

Add this to code injection - Footer

<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = location.pathname;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
      selectTag.style.fontWeight = "bold";
    }
  }
})()
</script>

 

Thanks for the reply @bangank36, I appreciate it! 

I changed the current state to be an underline. However, whether bold or underline, it's not quite working. It appears only if refreshing every time, on every page. Even on the main blog page where neither tag has been selected, one shows selected on refresh.

 

Link to comment
  • 8 months later...

@tuanphan @bangank36 Is there a solution that would work under Design > Custom CSS? I am trying to do the same thing - when someone clicks a category at the top (all, motion graphics, or editing), the selected/currently viewing category should stay the hover color. Here is the custom CSS I already applied to the categories, if it makes a difference. Here is my website, pass: pqrs. Thank you!

//tag cloud
.sqs-tagcloud li a {
    color: rgb(67, 45, 199);
    background-color: #00000;
    font-style: regular;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 18px;
-webkit-transition: .15s ease-out;
-moz-transition: .15s ease-out;
transition: .15s ease-out;
}

//tag cloud:hover
    .sqs-tagcloud li a:hover {
    background-color: rgba(173, 161, 242, .2);
}

 

Link to comment

This css code only sets the style when you hover the tag cloud.

If you want to set the hover style for the active tag, we need to implement javascript to work around with it

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

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 months later...
On 1/3/2022 at 10:06 PM, Beyondspace said:

Add this to code injection - Footer

<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = location.pathname;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
      selectTag.style.fontWeight = "bold";
    }
  }
})()
</script>

 

Hello,

Based on the turn off Ajax loading suggestion in the thread, I'm assuming this script is for 7.0.

I'm using 7.1 and the first tag is always bolded, no matter which ?tag= has been clicked. Do you have any suggestions for how to make the script work in 7.1?

My site is https://shop.digglesphotography.com

Thank you for any help you can offer.

Warren

 

Link to comment

A programmer friend helped me by adjusting the above code to get it to work on my site. I'm assuming these adjustments are needed to get it working in SS 7.1.

The code below will add an underline to the active tagcloud anchor tag
 

<!--- Add style="text-decoration: underline;" for currently selected tag filter -------------------------->
<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = window.location.pathname + window.location.search;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
      selectTag.style.textDecoration = "underline";
    }
  }
})()
</script>

Instead of adding a style, I want to add a class. With my limited JS knowledge I was able to accomplish it by modifying the above script like this

<!--- Add class="tag-active" for currently selected tag filter -------------------------->
<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = window.location.pathname + window.location.search;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
	  selectTag.classList.add("tag-active");
    }
  }
})()
</script>


 

Edited by Diggles
Link to comment
  • 1 month later...
On 12/5/2022 at 9:45 AM, Diggles said:

A programmer friend helped me by adjusting the above code to get it to work on my site. I'm assuming these adjustments are needed to get it working in SS 7.1.

The code below will add an underline to the active tagcloud anchor tag
 

<!--- Add style="text-decoration: underline;" for currently selected tag filter -------------------------->
<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = window.location.pathname + window.location.search;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
      selectTag.style.textDecoration = "underline";
    }
  }
})()
</script>

Instead of adding a style, I want to add a class. With my limited JS knowledge I was able to accomplish it by modifying the above script like this

<!--- Add class="tag-active" for currently selected tag filter -------------------------->
<script>
(function() {
  const tagCloud = document.querySelector(".sqs-tagcloud");
  if (tagCloud) {
    const currentPath = window.location.pathname + window.location.search;
    const selectTag = tagCloud.querySelector(`li a[href*='${currentPath}']`);
    if (selectTag) {
	  selectTag.classList.add("tag-active");
    }
  }
})()
</script>


 

Is this still the code you used for your site? It looks great! I'm trying to do something similar but the code isn't working. 

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.