Last active
April 27, 2016 20:18
-
-
Save feliciaceballos/23a34338f904871a7326ce8029b3c08f to your computer and use it in GitHub Desktop.
Reference Custom Single Post Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a constant path to plugin folder | |
define(SINGLE_PATH, plugin_dir_path( __FILE__ ). '/templates'); | |
// Filter the single_template with our custom function | |
add_filter('single_template', 'my_single_template'); | |
function my_single_template($single) { | |
global $wp_query, $post; | |
$user_role = get_user_role(); | |
$category = get_the_category(); | |
$sticky = is_sticky(); | |
$tag = has_tag( 'tag-name' ); | |
$post_status = get_post_status () == 'future'; | |
if ($post->post_type == 'client' && $user_role == 'client') : | |
return SINGLE_PATH . '/client-portal.php'; | |
elseif (in_category('export') && $post->post_type == 'client' ) : | |
return SINGLE_PATH . '/export.php'; | |
elseif (in_category('new-lead') && $post->post_type == 'client' ) : | |
return SINGLE_PATH . '/print-lead-sheet.php'; | |
else : | |
return SINGLE_PATH . '/lead-sheet.php'; | |
endif; | |
return $single; | |
} | |
// Get user role | |
function get_user_role() { | |
global $current_user; | |
$user_roles = $current_user->roles; | |
$user_role = array_shift($user_roles); | |
return $user_role; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment