Page 1 of 1

Hide specific content on specific pages

PostPosted: July 9th, 2011, 6:03 am
by hazardous_waster
Hello All!

Right I've had a look round the forums and can't find how to do this one. What my client wants to do is when a user is loged on to the site they'll see an extra chunk of content with extra content in at the bottom of the pages, so what I'd like is some sort of tag I can put on a div (don't mind if its ard coded in to the page template) or something I can wrap around said chunk of content so that'll only display to people who are loged in ... I had a look at the tags thing in s2member but that goes about about specific posts or pages ... not taging content on pages.

make sense? possible?

Thanks in advance,
Neil Kelsey

Re: Hide specific content on specific pages

PostPosted: July 9th, 2011, 7:09 am
by cassel
For having done it myself, you can use the conditionals to insert content. Something like this:

Content for everyone to see.
[s2If is_user_logged_in()]
Content for anyone that is logged in, regardless of their Membership Level.
[/s2If]


So whatever is wrapped in the conditional will only be displayed to logged in members. The others will not even see there is something there. And of course, the conditionals like that can take many forms and get more complex. Just as an example:
http://scrapbookcampus.com/basic-tutori ... tshop-pro/

In that page, some content is viewable by ALL, but if you are logged in, some content will appear, other will disappear, and if you are a paying member, still different content will display. It is fun to play with!

Re: Hide specific content on specific pages

PostPosted: July 9th, 2011, 7:13 am
by hazardous_waster
perfect!! Just tried it works a treat, thank you!

Re: Hide specific content on specific pages

PostPosted: July 11th, 2011, 1:13 pm
by hazardous_waster
Ok one further point .. I really need to do a similar thing to this but on a template, they want a different link box to appear if the user is loged in or not so I gotta use some HTML, but the editor seems to strip any html out I put in (pain in the ***) ... is that possible too?

N

Re: Hide specific content on specific pages

PostPosted: July 11th, 2011, 1:23 pm
by cassel
Are you typing the codes in the Visual or the HTML format? Which editor are you using?

Re: Hide specific content on specific pages

PostPosted: July 11th, 2011, 1:42 pm
by hazardous_waster
I've got these sorts of codes working just fine in the Wordpress page wysiwyg editor

[s2If is_user_logged_in()]
Content for anyone that is logged in, regardless of their Membership Level.
[/s2If]

But what I'm asking is can I on a page template, say I make a new one called 'switching-content.php' is there something I can write to do a similar thing for example

<? if (user is loged in)
{
<div> display this lovely div! </div>
} else
{
<div> they'll see this horrible one! </div>
} ?>

Yeah as you can see I'm no php coder, but I hope that explains what I'm after

Re: Hide specific content on specific pages

PostPosted: July 11th, 2011, 1:45 pm
by PseudoNyhm
I had similar editor issues with WordPress, especially when trying to insert HTML, PHP, JavaScript, or even just shortcodes. The trouble is that even if you use the so-called HTML editor, or turn off the Visual editor in the admin user preferences, the WordPress HTML editor still inserts line breaks, paragraph tags, and performs other formatting, which breaks code.

I recently installed TRUEedit, which allows you to switch off the WordPress formatting. This makes the HTML editor a true source editor (what you type will be what ends up as the page source).

Re: Hide specific content on specific pages

PostPosted: July 11th, 2011, 1:50 pm
by cassel
I am not coder either but if you look under API / Scripting > Advanced Conditionals, you might find other codes to enter. I am not 100% it will work but worth a try until someone more knowledgeable chimes in.

Re: Hide specific content on specific pages

PostPosted: July 11th, 2011, 8:54 pm
by Cristián Lávaque
PseudoNyhm wrote:I recently installed TRUEedit, which allows you to switch off the WordPress formatting. This makes the HTML editor a true source editor (what you type will be what ends up as the page source).


Brilliant tip! Thanks! :D

cassel wrote:I am not coder either but if you look under API / Scripting > Advanced Conditionals, you might find other codes to enter. I am not 100% it will work but worth a try until someone more knowledgeable chimes in.


Correct. :)

Re: Hide specific content on specific pages

PostPosted: July 18th, 2011, 2:01 pm
by hazardous_waster
Still having troubles with this trying to find a solution .. seems like it should be such a simple thing to do I thought I'd give it another shot, anyone else had any joy trying to do something similar?

Re: Hide specific content on specific pages

PostPosted: July 19th, 2011, 10:33 pm
by Cristián Lávaque
Take a look at the documentation here WP Admin -> s2Member -> API / Scripting -> Advanced/PHP Conditionals -> Example #1.

Code: Select all
<?php if(is_user_logged_in()){ ?>
    Content for anyone that is logged in, regardless of their Membership Level.
<?php } else { ?>
    Some public content.
<?php } ?>


I hope that helps.