I’m not sure how best to explain this. With the code that mores provided, it is possible to NOT use a plugin to create member-only sections.
How does it work?
I’m presuming you have an understanding of how a page template works, and bearing in mind I have not tested this code: This particular part <?php if (is_user_logged_in()) { ?>
sets a condition:
If the user is logged, they can see the content after this code and before the closing tag.
Example:
<?php if (is_user_logged_in()) { ?>
Oranges and lemons
<? } ?>
If the user is logged in, they can see ‘Oranges and lemons’. If they’re not, they can’t and the page is blank.
But let’s presume you want to inform the users who aren’t logged in that they have to login to see this content.
So this is where the else
comes in.
<?php if (is_user_logged_in()) { ?>
Oranges and lemons
<? } else { ?>
You must be logged in!
<? } ?>
Anyone who isn’t logged in will see ‘You must be logged in!’ And you can easily put a link to the login page.
I’m not quite sure how else to explain this, but this sort of explanation worked for me (and I’m a slow learner) so hopefully you’ll find it helpful too.