The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Hide some topics via script?

View previous topic View next topic Go down

Solved Hide some topics via script?

Post by betclever on 9/11/2014, 02:10

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 11/11/2014, 19:59; edited 1 time in total

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 on 9/11/2014, 02:20

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 http://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);
avatar
Ange Tuteur
Forumaster

Male Posts : 13176
Reputation : 2881
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 9/11/2014, 04:32

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?

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 on 9/11/2014, 04:38

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.
avatar
Ange Tuteur
Forumaster

Male Posts : 13176
Reputation : 2881
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 9/11/2014, 04:47

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

Thanks a lot!

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 on 9/11/2014, 05:50

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,

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 on 9/11/2014, 06:58

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';
 }
});
avatar
Ange Tuteur
Forumaster

Male Posts : 13176
Reputation : 2881
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 10/11/2014, 20:13

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)

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 on 11/11/2014, 00:22

So you want to hide the content of messages for guests ? Like this :


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
avatar
Ange Tuteur
Forumaster

Male Posts : 13176
Reputation : 2881
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 11/11/2014, 02:43

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

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 on 11/11/2014, 05:13

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.
avatar
Ange Tuteur
Forumaster

Male Posts : 13176
Reputation : 2881
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 11/11/2014, 19:58

It works perfectly Ange tuteur !

Thanks for this.

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 on 11/11/2014, 20:42

Topic solved and archived



avatar
APE
Manager
Manager

Male Posts : 11006
Reputation : 1031
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

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

Back to top Go down

View previous topic View next topic Back to top


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