Last Updated: February 25, 2016
·
1.308K
· kasparsb

Wordpress theme wrapper

class Your_theme_name {
    private static $ins;

    public static function init() {
        if ( !isset( self::$ins ) ) {
            $cn = __CLASS__;
            self::$ins = new $cn;
        }   
    }


    /**
      * Use theme method in your template files like this
      * Your_theme_name::some_method()
      */
    public static function some_method() {
        return self::$ins->special_posts;
    }


    private $special_posts = array();

    /**
      * Your theme logic goes here
      */
    public function __construct() {
        add_action( 
            'wp_enqueue_scripts', 
            array( $this, 'enqueue_scripts' ) 
        );

        $this->load_special_posts();
    }

    public function enqueue_scripts() {
        // Your scripts and css goes here
    }

    private function load_special_posts() {
        $this->special_posts = get_posts(....);
    }
}
Your_theme_name::init();

1 Response
Add your response

nice 1

over 1 year ago ·