Closing comments on community posts

6 Comments

  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Hello Jason Kaiser,

    I tried something for you but not with the API, only using JS. You can hide the comment box on the old post and show a link to redirect to the new post page.

     

    Here, I'm checking a specific date to disable comments on old posts.

     var _x = document.querySelector(".post li.meta-data > time");
      var _y = _x.innerHTML;
      var _z = document.querySelector('.post-comments');
      console.log(_y);
      
      if(_y === 'June 22, 2020') { // add your specific date
        _z.style.display = 'none';
        var _v = document.querySelector(".post .comment-overview p.comment-callout");
      _v.innerHTML = "<a href='#'> This is the text which has been inserted by JS </a>";
      }

     

     

    1. After adding this code snippet, you need to enter your specific date into the -  if(_y === 'ENTER YOUR SPECIFIC DATE') {.
    2. Add new post page URL into the href of anchor tag - _v.innerHTML = "<a href='#'>.
    3. You can write your text and remove this - This is the text which has been inserted by JS.

     

     

    You can check any attribute value in if() condition and hide or do something with the comment form of the post page.

    You can get attribute of (".post li.meta-data > time") and check the value with if().

     

     

    Please let me know if it works for you :)

     

    Thanks

    Team

     

     

    0
  • Jason K

    Thanks Ifra Saqlain, let me give it a try and see how it works out.

    0
  • Jason K

    Hi Ifra Saqlain, this solution worked for us! I appreciate you sharing. 

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Cheers! happy to hear.

    0
  • Jason K

    Hey Ifra Saqlain, I was curious if you had any advice for how to manipulate the code above to either:

    1. Target a specific community topic
    2. Target a rolling date (meaning "any post older than x number of years")

    Thank you 🙂

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Hey Jason Kaiser,

    Here we go --

     

    1. Target a specific community topic

     

    $(document).ready(function(){

      var getID = $('.breadcrumbs li:nth-child(3) a').attr('href').match(/[0-9]+/)[0];
      if (getID == '00000000'){
        $("WRITE CLASS NAME OR ID TO DO SOMETHING").hide();
      } else {
        $("WRITE CLASS NAME OR ID TO DO SOMETHING").show();
      }

    });






    Note: In the if condition, the 0000000 would be topic ID, so remove these zeros and add your topic ID. To get the topic ID, see the below instructions -

     

    To get the topic IDs - 

    1- Go to that post where you want to change something accordion to the topic ID.

    2- Now, see in the search bar on your screen.

     

    3- As you can see, those numbers are the topic ID, I wrapped those in red border.

    4- Copy those numbers, go to the script code, remove 000000 and paste this ID.

     

     

     

    Your second query is:

    1. Target a rolling date (meaning "any post older than x number of years")

     

    Here you only need to change the year - remove 21 and add yours.

    var _x = document.querySelector(".post li.meta-data > time");
      var _y = _x.innerHTML;
    var numYear = _y.slice(-2);
    console.log(numYear);
      var _z = document.querySelector('.post-comments');
     
    if(numYear === '21') {   // add your specific number of year
        _z.style.display = 'none';
        var _v = document.querySelector(".post .comment-overview p.comment-callout");
        _v.innerHTML = "<a href='#'> This is the text which has been inserted by JS </a>";
      }





    Note: you can change the year as 22, 21, 20, 19, 18, etc. I'm checking 21 you can change it.

     

     

     

     For multiple years:

    var _x = document.querySelector(".post li.meta-data > time");
      var _y = _x.innerHTML;
    var numYear = _y.slice(-2);
    console.log(numYear);
      var _z = document.querySelector('.post-comments');
     
      if(numYear === '21') {   // add your specific number of year
        _z.style.display = 'none';
        var _v = document.querySelector(".post .comment-overview p.comment-callout");
        _v.innerHTML = "<a href='#'> This is the text which has been inserted by JS </a>";
      }else  if(numYear === '22') {   // add your specific date
        _z.style.display = 'none';
        var _v = document.querySelector(".post .comment-overview p.comment-callout");
        _v.innerHTML = "<a href='#'> This is the text which has been inserted by JS </a>";
      }

     

     

    If any query do let me know :)

     

    Thanks

    Team

     

    0

Please sign in to leave a comment.

Powered by Zendesk