Show page content to certain members

Discussion in 'Setting-up protection' started by itsrich, Apr 7, 2015.

  1. itsrich

    itsrich Member

    Joined:
    Sep 13, 2014
    Messages:
    52
    Hello,

    How do I display certain page content to certain members?

    I don't want to protect the whole page, I just want to show certain parts of the page to certain members.

    As an example, I have a button on a page that links to a certain area to purchase product X, I want this to be displayed to members that don't have product X, but then I want the button hidden from those that do have product X.

    Thank you
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    I guess you are not using wordpress?
    For regular pages this is possible only if your pages are php.
    Add this line to the top of your php page:
    PHP:
    <?php
    include_once("/full/path/to/amember/library/Am/Lite.php");
    ?>
    then when you what to display that block:
    PHP:
    <?php if(Am_Lite::getInstance()->haveSubscriptions(array(1,2,3))) : ?>
    This block will be included only when user has active subscriptions to product 1 or 2 or 3.
    <?php endif; ?>
    doyo likes this.
  3. itsrich

    itsrich Member

    Joined:
    Sep 13, 2014
    Messages:
    52
    Hi Alexander,

    No I don't have wordpress installed, I just have Xenforo integrated.

    Is there any documentation on other information that can be obtained? For instance, if I wanted to target certain member ids, product categories, members that have expired product X? etc.

    Thank you for your help
    Last edited: Apr 8, 2015
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
  5. powerkeys

    powerkeys Member

    Joined:
    Aug 29, 2006
    Messages:
    192
    Just checking, does the PHP method described in this thread work with protected pages created within aMember?

    I'd like to set up pages to provide a custom display of the files contained within the products, and display an upgrade link to members who have the "basic" version of the package and want to gain access to the "deluxe" version files as well.

    That brings up another question. Is there a way to display an upgrade link on a protected page? In this, I'm referring to the upgrade link that is automatically displayed on the dashboard to a member who qualifies for an upgrade path.

    If not, then is it possible to display the upgrade link on the "Access Denied" page when appropriate?

    Thanks.
  6. powerkeys

    powerkeys Member

    Joined:
    Aug 29, 2006
    Messages:
    192
    For others looking for an answer to this question, I think I may have found the solution.

    The basic idea is that for each protected page created in aMember, you can define a separate template, and templates can use PHP code.

    So, the answer is to create a custom template that will use the API to check user status and access permissions, and then display content based on those values. The example above is one way to do this within a template file.

    Now, we just need to get Alex and the team to add a feature so non-programmers can define conditional content in protected pages.

Share This Page