Skip to content

Instantly share code, notes, and snippets.

View zanematthew's full-sized avatar

Zane Matthew zanematthew

View GitHub Profile
@zanematthew
zanematthew / tracks_controller.php
Created May 9, 2012 23:12
Sample code from the tracks controller
<?php
// Contents of controllers/tracks_controller.php
Class Tracks extends zMCustomPostTypeBase {
/**
* @todo derive this, based on $this->post_type['type']
*/
public $cpt = 'tracks';
@zanematthew
zanematthew / events.php
Created May 9, 2012 22:58
This the contents of our Events Post Type
<?php
// This file is located in models/events.php
$tmp_cpt = 'events';
$event = new Events();
$event->post_type = array(
array(
'name' => 'Race Event',
'type' => $tmp_cpt,
'has_one' => 'tracks', // add support 'has_many' => 'other_cpt'
// Old js snippet, would be better to move this to the template, the thing is if there's no results this should not be displayed.
new_header = '<tr><th class="attending">Add</th><th class="date">Date</th><th class="title">Event</th><th class="track">Track</th><th class="state">State</th></tr>';
// snippet of search.js
// Start
var results_data_object = {"result":[]};
results_data_object.result.push({
id: this_result['ID'],
title: this_result['t'],
track: this_result['tr'],
@zanematthew
zanematthew / gist:2634706
Created May 8, 2012 12:56
Sample using JavaScript templating.
// The JS Template
<script id="result_event_tpl" type="text/html">
{{#result}}
<tr>
<td>
<input type="checkbox" {{checked }} class="yes_no_handle {{ css_class }}" data-action="{{ action }}" data-current_user_id="{{ current_user }}" data-post_id="{{ id }}" />
</td>
<td class="meta">{{ date }}</td>
<td>
<div class="title">
@zanematthew
zanematthew / routes.php
Created May 3, 2012 13:40
This is the entire routes file, this is inspired by Rails routes.rb file.
<?php
/**
* Any Custom Post Type "should" automatically be routed based on the following:
*/
add_action('template_redirect', function( $params=array() ) {
$post_type = null;
$taxonomy = get_query_var('taxonomy');
@zanematthew
zanematthew / bootstrap.php
Created May 3, 2012 13:39
This is a snippet from bootstrap.php which acts as an auto loader based on scan dir.
<?php
// This will auto load the following and/or create files if needed.
//
// plugin/controllers/$post_type_controller.php
// plugin/models/$post_type.php
// plugin/assets/stylesheets/$post_type.php
// plugin/assets/javascripts/$post_type.php
//
// note as of now the oder of the files is not important, we'll cross
@zanematthew
zanematthew / abstract.php
Created May 2, 2012 13:42
The abstract class for creating Custom Post Types
<?php
/**
*
* This is used to regsiter a custom post type, custom taxonomy and provide template redirecting.
*
* This abstract class defines some base functions for using Custom Post Types. You should not have to
* edit this abstract, only add additional methods if need be. You must use what is provided for you
* in the interface.
*
*/
@zanematthew
zanematthew / gist:2500075
Created April 26, 2012 14:45
Custom action for WordPress Template Redirect
<?php
/**
* Determine if given templates exists if they do loads them
* based on the type of page being displayed.
*
* @uses is_single()
*/
if ( ! function_exists( '_zm_template_redirect' ) ) :
function _zm_template_redirect( $params=array()){
@zanematthew
zanematthew / gist:2500025
Created April 26, 2012 14:42
Filters for WordPress Template Redirect with Custom Taxonomies and Custom Post Types
<?php
/**
* An "easier" interface for interacting with WordPress' template_redirect function.
*
* @package zm-wordpress-helpers
* @uses is_admin()
* @uses get_query_var()
*/
function bmx_race_schedule_redirect( $params=array() ) {
<?php
ini_set('display_errors', 'on');
error_reporting( E_ALL );
/**
* Settings
*/
global $_closure;
global $_p_head_dir;