latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

s2If conditional – adding to large website

Home Forums Community Forum s2If conditional – adding to large website

This topic contains 4 replies, has 2 voices. Last updated by  Bruce 3 years, 5 months ago.

Topic Author Topic
Posted: Wednesday Jul 24th, 2013 at 5:09 am #53967

Hi there,

Can you help please?

We have followed these steps:

Dashboard -› s2Member® -› API / Scripting -› Simple/Shortcode Conditionals

Select the s2If conditional

However, the developer I am using has come back with the following response:

“If we like to use shortcode solution we need to edit all post/page and add [s2If current_user_can(access_s2member_level1)] on every post/page editor. I believe this will take much time since you al ready have thousand content.
use PHP/API, update theme, single.php

We can do this automatic with clear the restriction option and add a new code when people open single content. But your requirement (80 words) is not easy.

I will need to strip the tags, that mean you will loose content formatting (like bold, italic, underline etc) from content sample.
My question is which method do you like to use?
Is that okay if we strip content format if we use PHP/API solution? Stripped content will be shown to not login user/not member only.”

We have thousands of posts and do not want to strip back any formatting on the posts (understandably), nor do we want to go onto every page and add the code individually.

Is there an easier/better way to do this?

Thanks

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Wednesday Jul 24th, 2013 at 5:27 am #53974
Bruce
Username: Bruce
Staff Member

Thank you for your inquiry.

Is there an easier/better way to do this?

This idea is the easiest way to get this working for you:

We can do this automatic with clear the restriction option and add a new code when people open single content. But your requirement (80 words) is not easy.

What you’d do is edit either your theme’s page.php or single.php file (depending on what your theme uses for displaying these Posts/Pages), and use s2Member’s Advanced PHP Conditionals to decide whether to show the first 80 words of the Post, or the entire post.

See: Dashboard -› s2Member® -› API / Scripting -› Advanced PHP Conditionals

The idea of grabbing a “snippet” of a Post is not that uncommon, and your developer can probably find examples on how to do that pretty easily. You only need to accomplish that, and decide when to use it. Here’s some psuedo-code for this, assuming that you’re wanting Users to be s2Member Level 1 or higher to see full Page content:

<?php if(!current_user_can('access_s2member_level1')) /* If the User can't access s2Member Level 1 or higher... */ { ?>
	...then we show the snippet.
<?php } else { ?>
	Otherwise we show the whole page's content.
<?php }?>
Posted: Wednesday Jul 24th, 2013 at 5:52 am #53975

Hi Bruce,

Thanks for this.

Do you know of any examples of grabbing snippets of code? My developer seems to be struggling with this, and I don’t know enough to help…

Thanks

Posted: Wednesday Jul 24th, 2013 at 5:53 am #53976

Hi Bruce,

Sorry I meant to say that he is struggling to find a solution for showing a snippet of the post without losing formatting like bold, underline, links etc…

do you know of any simple ways of doing this?

Posted: Wednesday Jul 24th, 2013 at 7:53 pm #54005
Bruce
Username: Bruce
Staff Member

Sorry I meant to say that he is struggling to find a solution for showing a snippet of the post without losing formatting like bold, underline, links etc…

The absolute simplest way to accomplish this would be to use the WordPress capability for this, which is based on characters rather than words. There’s lots of examples for that here:

http://codex.wordpress.org/Function_Reference/get_the_excerpt

If you absolutely only want the first 50 words, you’ll need some simple regex. Here’s a StackOverflow topic on doing this:

http://stackoverflow.com/questions/5419969/selecting-50-words-from-a-string

Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.