Creating a Table of Contents - YourMembers/yourmembers GitHub Wiki

If you've already gone through the various content protection methods available with the Your Members WordPress membership plugin, you can now put them to good use and create a helpful table of contents that only users will see.

The Shortcodes You'll Need to Know About

The main shortcodes used to make a table of contents are the private_and tag ([private_and]), and the user_has_access tag ([user_has_access]) tag, which you can learn about here.

Here's how they should look, if you're using them properly:

[private_and #xxx]Content goes here.[/private_and] [user_has_access #xxx]Content goes here.[/user_has_access]

The xxx in the shortcodes should be substituted with the appropriate post/page ID.

The private_and tag will look at the current page AND the other page identified by the ID number. It will only return information if both are correct and return true. It will also display an error if it's incorrect. User_has_access will only check the post defined in the code and will not return anything if it returns false.

If you want to check for both pages, you'll need to wrap it in a private tag. So, it should looks something like this:

[private] [user_has_access #xxx]Content would go here.[/user_has_access] [/private]

If the user doesn't have access to the post defined in the code, it will not return anything. If the user has access to the post defined in the code, but not the current post the code is on, it will return an error message.

Build a Simple Table of Contents

All you need to do to create a basic table of contents is set up your content and code like this:

[user_has_access #1] Hello World [/user_has_access]

http://example.com/hello-world is post ID 1. So, the content in the user_has_access tag will only appear if the user has access to post 1.

Creating a Table of Contents for Specific Account Type Groups

Want to create a table of contents for members with a specific account type? Let's say you have three account types: bronze, silver, or gold. Let's build a table of contents for bronze-level members.

[ym_user_is package_type="bronze"] URLs will be listed here [/ym_user_is]

There are a few things to remember here, however. Because account types aren't hierarchical, this list of URLs won't include posts or pages available to other account types. So, for example, if someone has a gold-level subscription, and you set up a table of contents for them, they won't have access to posts included in the silver and bronze account types. If you've shared content with more than one account type, use the user_has_access tag to ensure all of the URLs are listed here.

So, for example:

[ym_user_is package_type="bronze"] [user­_has_access #22]Content here.[/user_has_access] [/ym_user_is]

This would show content to users with a bronze account type, who also has access to post/page 22. A gold-level subscription holder would not see the content, even if they have access to post 22 because they don't satisfy the first requirement: the subscription type.

An Example of a Complete Table of Contents

Now, let's assume you're running a two-tier website, which has two account types: free and premium. Let's say free users will get access to all the content over time. Premium users, however, get instant access to all the content, as well as a special list of premium posts and pages.

Here is how the table of contents would look:

Basic Introduction [ym_user_has_access #2] Page 2 [/ym_user_has_access] [ym_user_has_access #3] Page 3 [/ym_user_has_access] [ym_user_has_access #4] Page 4 [/ym_user_has_access] [ym_user_has_access #5] Page 5 [/ym_user_has_access] [ym_user_has_access #6] Page 6 [/ym_user_has_access] [ym_user_has_access #7] Page 7 [/ym_user_has_access]

Premium content [ym_user_is package_type="premium"] Premium 1 Premium 2 Premium 3 Premium 4 [/ym_user_is] [ym_user_is package_type="free"] You don't have access to the premium content, why not upgrade today! [/ym_user_is]

As you can see, premium members can access all of the content. Free users, on the other hand, will only see the content as it becomes available (if you're drip feeding or delaying the content). Free users will also see an upsell message encouraging them to upgrade, instead of the premium content.

⚠️ **GitHub.com Fallback** ⚠️