Recent searches


No recent searches

Closing comments on community posts

Answered


Posted Jan 28, 2022

Hi @...,

Back in May of last year you provided some helpful information about potentially using the API to move or delete posts from a particular date range. It seems the post has been deleted as my original links to it no longer work. I was hoping to get some information about identifying community posts of a specific date range and closing them for comments. Is this possible?

The use-case is:

We are a software company and as such, a lot of our older posts report issues and provide feedback about a state that our software is no longer in. In an effort to encourage folks to start create new posts instead of commenting on old posts we were hoping to close comments on posts before a certain date. 

Any advice or info would be greatly appreciated.


1

6

6 comments

image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

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


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

0


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

0


image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

Cheers! happy to hear.

0


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


image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

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.

Didn't find what you're looking for?

New post