Skip to content

Instantly share code, notes, and snippets.

View cassler's full-sized avatar

Darin Cassler cassler

View GitHub Profile
@cassler
cassler / dynamic_collapse.js
Last active August 29, 2015 14:24
Dynamic Collapse Size
var a = $('#navbar-31536'); // container element
var b = $('ul.nav.navbar-nav li a').height(); // height of the menu
function UsmDynamicCollapse(a, b) {
var navbar = a;
var height = b;
navbar.removeClass('collapsed'); // set standart view
if(navbar.innerHeight() > height ) // check if we've got 2 lines
navbar.addClass('collapsed'); // force collapse mode
}
@cassler
cassler / printp.php
Last active August 29, 2015 14:14
Rich Print R
function print_p($value = false, $exit = false, $return=false, $recurse=false) {
if ($return === true && $exit === true)
$return = false;
$tab = str_repeat(" ", 8);
if ($recurse == false) {
$recurse = 0;
$output = '<a class="btn btn-primary" type="button" data-toggle="collapse" data-target="#debugInfo" aria-expanded="false">
Debug Info
</a><pre id="debugInfo" class="collapse" style="width:100%; height:1px; border: 1px dotted #ccc; background-color: #eee; display: block; padding: 20px;">';
$backtrace = debug_backtrace();
@cassler
cassler / get-post-by-slug.php
Created January 14, 2015 17:25
Don't use IDs directly, go right for the slug!
<?php
/**
* Get ID by Page Slug
*
* You'll often need to get content for a specific post object and render it somewhere else. We want to avoid
* using hard-coded ID's because we need to maintain portability of our work. This function aids that process without
* introducing too much overhead. In fact, it's arguably easier to develop this way. Further, its more efficient
* computationally.
*
* BACKGROUND:
@cassler
cassler / team.php
Created December 6, 2014 15:50
Team Custom Post Type & Shortcode
<?php
add_action( 'after_setup_theme', 'usm_custom_post_types' );
function usm_custom_post_types() {
if ( ! class_exists( 'Super_Custom_Post_Type' ) )
return;
$team = new Super_Custom_Post_Type( 'team', 'Team Member', 'Team Members' );
$team->set_icon( 'group' );
$team->add_meta_box( array(
@cassler
cassler / model.php
Last active August 29, 2015 14:10
Team CPT
add_action( 'after_setup_theme', 'cb_custom_post_types' );
function cb_custom_post_types() {
if ( ! class_exists( 'Super_Custom_Post_Type' ) )
return;
$team = new Super_Custom_Post_Type( 'team', 'Team Member', 'Team Members' );
$team->set_icon( 'group' );
$team->add_meta_box( array(
'id' => 'hr-details',
@cassler
cassler / post-type.php
Created November 26, 2014 16:54
Testimonials with SuperCPT
<?php
add_action( 'after_setup_theme', 'cb_data_model' );
function cb_data_model() {
if ( ! class_exists( 'Super_Custom_Post_Type' ) )
return;
## TESTIMONIALS MODEL
$testimonials = new Super_Custom_Post_Type( 'testimonial', 'Testimonial', 'Testimonials' );
$testimonials->set_icon( 'comment' );
@cassler
cassler / theme_image.php
Created September 11, 2014 15:05
Simple Theme Images
<?php
/**
* Simple function to streamline using image assets in your theme
*
* @author Darin Cassler
* @uses Wordpress
* @param string $src Required. The name of your image asset
* @param string $alt Optional. The alternate next for your img tag, if left blank - will use the image name.
* @param string $path Optional. This is the path inside your theme where images are stored. Defaults to /img/.
* @var $alt - Alt text for your image
@cassler
cassler / filter-by-name.php
Created July 14, 2014 16:32
Filter by Last Name
/**
* Filters posts by last word in title
*
* Particularly useful for sorting staff lists by last name alphabetically
**/
function posts_orderby_lastname ($orderby_statement) {
$orderby_statement = "RIGHT(post_title, LOCATE(' ', REVERSE(post_title)) - 1) ASC";
return $orderby_statement;
}
@cassler
cassler / pre-query-data.php
Last active August 29, 2015 14:03
Order events by Data
<?php
function order_events_by_date($request){
$dummy_query = new WP_Query();
$dummy_query->parse_query( $request );
if($dummy_query->is_singular()):
return $request;
elseif(isset($request['post_type']) && $request['post_type'] == 'event'):
if(!is_admin()):
$request['orderby'] = 'meta_value_num menu_order title';
$request['meta_key'] = array(array('event-date'),array('event-time'));
@cassler
cassler / iterm-mod.sh
Created June 27, 2014 18:04
Fix iTerm + Git on Yosemite
/**
* Type the following commands into terminal and start a new session
* this will fix any issues with Xcode not being able to git-pull in iTerm + ZSH
**/
cd /Applications/iTerm.app/Contents/MacOS
mv iTerm iTerm-bin
cat > iTerm <<EOF
#!/bin/sh