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 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

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 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 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);

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 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?

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 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

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

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 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,

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 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 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)

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 November 11th 2014, 12:22 am

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

Ange Tuteur
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

Post by betclever on 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

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 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
Forumaster

Male Posts : 13021
Reputation : 2683
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Hide some topics via script?

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

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 November 11th 2014, 8:42 pm

Topic solved and archived





APE
Manager
Manager

Male Posts : 8311
Reputation : 716
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