Skip to content

Instantly share code, notes, and snippets.

@mattonomics
Created May 12, 2012 20:57
Show Gist options
  • Save mattonomics/2668986 to your computer and use it in GitHub Desktop.
Save mattonomics/2668986 to your computer and use it in GitHub Desktop.
Thesis Skin with Custom Post Types
<?php
if (! defined('ABSPATH'))
die('Please do not directly access this file');
// classes are a VERY important part of 2.0, so you need to be familiar with them.
if (! defined('ABSPATH'))
die('Please do not directly access this file');
class thesis_skin_example extends thesis_custom_loop {
public function __construct() {
parent::__construct(); // this "activates" the Custom Loop API
add_action('init', array($this, 'init'));
}
public function init() {
$this->actions();
$this->filters();
$this->switch_skin();
// custom post type bits
$this->cpt();
}
// custom post type implementation
public function cpt() {
$args = array(
'labels' => array(
'name' => __( 'Products', 'your-custom-domain' ),
'singular_name' => __( 'Product', 'your-custom-domain' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'products')
);
register_post_type( 'acme_product', $args);
}
public function actions() {
// add and remove actions here
}
public function filters() {
// add and remove filters here
}
private function switch_skin() {
// Since after_switch_theme won't run, let's make sure that we generate the CSS
if (is_admin() && ! get_option(__CLASS__ . '_generate')) {
thesis_generate_css();
update_option(__CLASS__ . '_generate', 1);
wp_cache_flush(); // flush the cache so things don't break!
}
else return null;
}
// below this line, use methods from the Custom Loop API.
public function home() {
thesis_loop::home(); // remove this line and put your own home loop here
}
public function archive() {
thesis_loop::archive(); // remove this line and put your own archive loop here
}
}
new thesis_skin_example;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment