Hiding downvote totals on article pages

7 Comments

  • Pulkit Pandey
    Community Moderator

    Hi Michael Lorch

    You can hide the article votes button using the CSS.

    Let me know if you need any further assistance

    Thanks

    Pulkit
    Team Diziana

    0
  • Michael Lorch

    Pulkit PandeyThanks for getting back to me on this! May you provide further information? I just want the information at the bottom of an article to display the total number of helpful votes, not the total number of helpful votes out of all votes.

    Currently, it says something like '10 out of 17 users found this helpful'. I'd want it to say '10 users found this article helpful'. Can we do this?

    Thanks again for your time.

    0
  • Pulkit Pandey
    Community Moderator

    HiMichael Lorch

    This can be possible using theAPIwhere you need to get the list of votes based on the article and only list positive votes.

    Thanks

    Pulkit

    TeamDiziana

    0
  • Lucas Zhu

    Pulkit Pandey, I am a bit confused, the api can only list votes if I need the numbers, so what we want is to change the display on any article page from "77 out of 100 found this helpful" to "77 found this helpful" by removing "out of 100", do you know how I can edit the theme code to achieve this? Thank you.

    0
  • Christopher Kennedy
    Zendesk Developer Advocacy
    Hi Lucas,

    You can also use JS to pull the upvote count from the rendered label and replace the label's text without the downvote count. Here's an example that does this:

    const label = document.querySelector(".article-vote-label");
    const text = label.innerText;
    const position = text.indexOf("out of");

    label.innerHTML = text.slice(0 , position) + "found this helpful";
    0
  • Lucas Zhu

    Christopher Kennedy, thank you for the reply. I have added the code into article_page.hbs file like below, it did work for the first time, but when I click Yes or No button, the label text changed back to "xx out of xx found this helpful". Do you know anywhere else we need to change to keep " out of xx " always hidden under whichever situations? Thanks.


    {{vote 'label' class='article-vote-label'}}

    0
  • Christopher Kennedy
    Zendesk Developer Advocacy
    Hi Lucas,

    That's a good catch. What's happening is when the user changes the vote, a new vote label replaces the previous one that had updated text. So your script will need to track when a new label gets added due to a vote change and update the new label's text. One straightforward way to do this is to use JS'MutationObserver. Here's an example to demo:



    0

Pleasesign into leave a comment.

Powered by Zendesk