* @license GPL-2.0+ * @link http://rahularyan.com * @copyright 2014 Rahul Aryan */ class anspress_theme { /** * Instance of this class. */ protected static $instance = null; /** * Return an instance of this class. * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } return self::$instance; } public function __construct(){ add_filter( 'template_include', array($this, 'template_files'), 1 ); add_filter( 'comments_template', array($this, 'comment_template') ); add_action( 'after_setup_theme', array($this, 'includes') ); } // include required theme files public function includes(){ require_once ap_get_theme_location('functions.php'); } /* Template for single question */ public function template_files( $template_path ) { global $post; if ( 'question' == get_post_type() ) { if ( is_single() ) { $template_path = ap_get_theme_location('single-question.php'); } if ( is_tax( 'question_category' ) ) { $template_path = ap_get_theme_location('list.php'); } if ( is_tax( 'question_tags' ) ) { $template_path = ap_get_theme_location('list.php'); } if ( is_post_type_archive( 'question' ) ) { $template_path = ap_get_theme_location('list.php'); } if ( is_category() ) { $template_path = ap_get_theme_location('category.php'); } } if ( 'answer' == get_post_type() ) { if ( is_single() ) { global $post; wp_redirect( get_permalink($post->post_parent) ); exit; } } if($post){ // if ask page if( ap_opt('ask_page') == $post->ID ){ $template_path = ap_get_theme_location('ask.php'); } // if base page if( ap_opt('base_page') == $post->ID){ $template_path = ap_get_theme_location('index.php'); } // if question edit if( ap_opt('edit_page') == $post->ID){ $template_path = ap_get_theme_location('edit-question.php'); } // if edit answer page if( ap_opt('a_edit_page') == $post->ID){ $template_path = ap_get_theme_location('edit-answer.php'); } } return $template_path; } // register comment template function comment_template( $comment_template ) { global $post; if($post->post_type == 'question' || $post->post_type == 'answer'){ return ap_get_theme_location('comments.php'); } } }