WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using role based page templates? (3 posts)

  1. tanver
    Member
    Posted 3 years ago #

    Hi friends,
    I am working on a project where I need to restrict the contents [columns and no. of words to be displayed] based upon the role of the user, who is currently trying to access the contents.
    I am thinking of using User Based Page Templates like we do for page-catid.php etc but don't know whether it is possible or not? I would appreciate any help/support from this wonderful community.
    TIA

  2. vtxyzzy
    Member
    Posted 3 years ago #

    I believe that you could have a 'parent' template include the proper 'child' template based on the current user's capability. Something like this (UNTESTED):

    if (current_user_can('administrator')) {
       include TEMPLATEPATH . '/admin-template.php';
    } elseif (current_user_can('editor')) {
       include TEMPLATEPATH . '/editor-template.php';
    } else {
       include TEMPLATEPATH . '/norole-template.php';
    }
  3. tanver
    Member
    Posted 3 years ago #

    Thanks for your support. :)
    It did the job, have to replace TEMPLATEPATH with STYLESHEETPATH for the templates to be based in the child theme folder.

Topic Closed

This topic has been closed to new replies.

About this Topic