Simple Membership Plugin › Forums › Simple Membership Plugin › Display page templates based on membership levels
Tagged: membership levels, page templates
- This topic has 2 replies, 2 voices, and was last updated 10 years, 8 months ago by
JameyCodding.
-
AuthorPosts
-
October 27, 2015 at 6:22 pm #3688
JameyCodding
ParticipantHello. I’ve been developing a membership site using a different plugin and have since moved to Simple Membership because it had more of the functionality that I was looking for. However, there is one bit of functionality that I need to adapt from the old plugin to SM.
I had each page from the site using a custom page template based on the logged-in user’s membership level. This did not, however, affect the homepage (page id 5, from below). I’ve pasted the function that I worked through with the other plugin’s support team below.
Could you please let me know how to modify this to pull Simple Membership’s membership levels?
*************************
add_filter( 'page_template', 'custom_page_template' ); function custom_page_template( $page_template ){ // Global post variable global $post; /** * For all pages */ // Check if this is page if( $post->post_type == 'page' ){ if( $post->ID != 5 ) { if( current_user_on_membership( 2 ) ){ return get_stylesheet_directory() . 'template2.php'; } elseif( current_user_on_membership( 3 ) ){ return get_stylesheet_directory() . 'template3.php'; } } return $page_template; } return $page_template; } add_filter( 'single_template', 'get_post_template' ); function get_post_template( $template ) { if( current_user_on_membership( 2 ) ){ return get_stylesheet_directory() . '/template2.php'; } elseif( current_user_on_membership( 3 ) ){ return get_stylesheet_directory() . '/template3.php'; } } if( ! function_exists( 'current_user_on_membership' ) ) { function current_user_on_membership( $membership_id ) { $member = MS_Model_Member::get_current_member(); $membership_items = $member->get_membership_ids(); if( in_array( $membership_id, $membership_items ) ) { return true; } return false; } }October 27, 2015 at 9:24 pm #3692mbrsolution
ModeratorHi check the following documentation. There you will find the function to pull the membership level.
Regards
October 28, 2015 at 12:44 am #3696JameyCodding
ParticipantHi @mbrsolution, thanks for the info. I actually have tried modifying the code I posted using the documentation you mentioned. However, I’m not great with PHP so I can’t quite get it to work right, so I was hoping someone here could show me what I’m missing.
I know I need to replace “current_user_on_membership” in my function with Simple Membership’s information, but I don’t know what is supposed to go there. I’m also not sure what else may need to be changed in my existing function to get it working correctly.
Any help would be greatly appreciated. Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.