The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Hide some topics via script?

3 posters

Go down

Solved Hide some topics via script?

Post by betclever November 9th 2014, 2:10 am

Hi all,

Is there any script to hide some topics under some forums?

I know the procedure to hide a category or forum but not for topics... Sad


Thanks,


Last edited by betclever on November 11th 2014, 7:59 pm; edited 1 time in total
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by Ange Tuteur November 9th 2014, 2:20 am

Hello bet clever,

See if this is what you want :

Administration Panel > Modules > JavaScript codes management > Create a new script

Title : Your choice
Placement : In all the pages
Paste the code below :
Code:
$(function() {
  hideTopic(1);
  
  function hideTopic(id) {
    var a = document.getElementsByTagName('A'), reg = new RegExp('/t'+id),i;
    for (i=0; i<a.length; i++) if (reg.test(a[i].href)) a[i].style.display = 'none';
  }
});

Its function is to hide the link to the topic, if it contains the topic id. In the script you'll write : hideTopic(id);

id : the id of the topic. Example https://help.forumotion.com/t136620-hide-some-topics-via-script

/t136620 is where the id is, so to hide this topic's link I'd write :
Code:
hideTopic(136620);
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever November 9th 2014, 4:32 am

Thanks Ange tuteur but I forgot to say that I just want to hide some topics for guest users but for members, these ones have to be apparent.

Is this possible?
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by Ange Tuteur November 9th 2014, 4:38 am

See if this works :
Code:
$(function() { if (_userdata.user_id != -1) return
  hideTopic(1);
 
  function hideTopic(id) {
    var a = document.getElementsByTagName('A'), reg = new RegExp('/t'+id),i;
    for (i=0; i<a.length; i++) if (reg.test(a[i].href)) a[i].style.display = 'none';
  }
});

I added a condition to the top of the script.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever November 9th 2014, 4:47 am

Oh super!!!
I will try it as quickly as possible and keep you informed.

Thanks a lot!
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever November 9th 2014, 5:50 am

I got a question Ange tuteur.

How can I regroup in one script several topics to hide?

Shall I copy-paste each time the same code you have mentionned for each topic I want to hide or just a phrase?

Thanks,
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by Ange Tuteur November 9th 2014, 6:58 am

You can copy and paste hideTopic(); as much as you want.

Here is an example :
Code:
$(function() { if (_userdata.user_id != -1) return
  hideTopic(1);
  hideTopic(2);
  hideTopic(3);
  hideTopic(4);
  hideTopic(5);

  function hideTopic(id) {
    var a = document.getElementsByTagName('A'), reg = new RegExp('/t'+id),i;
    for (i=0; i<a.length; i++) if (reg.test(a[i].href)) a[i].style.display = 'none';
  }
});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever November 10th 2014, 8:13 pm

Hi,

Is there any possibility to view the topic for members however for guest users hide the analyses or the text inside the topics?

It will be great if I can leave a message to guest users to ask guests to register to view the content of this topic...

I don't know if it's possible of course but maybe add a condition like the one you have mentioned here:

Code:
{ if (_userdata.user_id != -1)
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by Ange Tuteur November 11th 2014, 12:22 am

So you want to hide the content of messages for guests ? Like this :
Hide some topics via script? Captur12

Script :
Placement : In the topics
Code:
$(function() {
  var guestText = '<span style="color:#F00">Please <a href="/login">login</a> or <a href="/register">register</a> to see this content.</span>',
      a = document.getElementsByTagName('DIV'),i;
  if (_userdata.user_id === -1) for (i=0; i<a.length; i++) if (/postbody/.test(a[i].parentNode.parentNode.className)) a[i].innerHTML = guestText;
});

The variable guestText is the content displayed to guests when they're logged out. You can change this anyway you want. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever November 11th 2014, 2:43 am

Ok super but where shall I put this script ?

I don't want to put this one for all topics but only for some topics?

Shall I put this script in the topic description or under scripts on the CP?

Thanks Ange tuteur
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by Ange Tuteur November 11th 2014, 5:13 am

Okay, try this :

Administration Panel > Modules > JavaScript codes management > Create a new script

Title : your choice
Placement : In the topics
Paste the code below :
Code:
$(function() {
  var guestText = '<span style="color:#F00">Please <a href="/login">login</a> or <a href="/register">register</a> to see this content.</span>',
      topics = [1, 2, 3, 4, 5, 6],
      a = document.getElementsByTagName('DIV'),i,j;
  if (_userdata.user_id === -1) for (j=0; j<topics.length; j++) if (topics[j] === Number(window.location.pathname.replace(/\/t(\d+).*/,'$1'))) for (i=0; i<a.length; i++) if (/postbody/.test(a[i].parentNode.parentNode.className)) a[i].innerHTML = guestText;
});

I added an array for topic ids :
Code:
topics = [1, 2, 3, 4, 5, 6]

Where the numbers are, is where you'll write the IDs of the topics you want the script to run in. You can add as many as you want, so long as the IDs are separated by commas.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever November 11th 2014, 7:58 pm

It works perfectly Ange tuteur !

Thanks for this.
avatar
betclever
Forumember

Posts : 209
Reputation : 2
Language : english

http://www.betclever.net

Back to top Go down

Solved Re: Hide some topics via script?

Post by Ape November 11th 2014, 8:42 pm

Topic solved and archived


Hide some topics via script? Left1212Hide some topics via script? Center11Hide some topics via script? Right112
Hide some topics via script? Ape_b110
Hide some topics via script? Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19084
Reputation : 1988
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum