Skip to content

Instantly share code, notes, and snippets.

View cassler's full-sized avatar

Darin Cassler cassler

View GitHub Profile
@cassler
cassler / wp-format-loop.md
Last active August 29, 2015 13:58
Post Format Detecting Loop

Use Details

You'll want to start by creating a file ```/content/loop.php`` - will be your default or "standard" format loop. For additional post format support, you'll need to add a loop file to match. For example, if your theme supports the post formats 'aside', 'video', and 'audio' then you should have:

  • /content/loop.php : Standard/Default View
  • /content/loop-aside.php : View for Aside Post Format
  • /content/loop-video.php : View for Video Post Format
  • /content/loop-audio.php : View for Audio Post Format

As you cycle through your loop, the correct template part will be rendered for each post format.

@cassler
cassler / curl-timer.sh
Last active August 29, 2015 14:02
Timed CURL
#!/bin/bash
CURL="/usr/bin/curl"
GAWK="/usr/bin/gawk"
echo -n "Please pass the url you want to measure: "
read url
URL="$url"
result=`$CURL -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} $URL`
echo " Time_Connect Time_startTransfer Time_total "
echo $result | $GAWK -F: '{ print $1" "$2" "$3}'
@cassler
cassler / purge-transients.php
Created June 6, 2014 20:03
Removes non-essential transients from DB
<?php
if ( ! function_exists('purge_transients') ) {
function purge_transients($older_than = '7 days', $safemode = true) {
global $wpdb;
$older_than_time = strtotime('-' . $older_than);
if ($older_than_time > time() || $older_than_time < 1) {
return false;
@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
@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 / 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 / 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 / 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 / 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 / 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(