Skip to content

Instantly share code, notes, and snippets.

View madysondesigns's full-sized avatar

Sarah Whinnem madysondesigns

View GitHub Profile
@madysondesigns
madysondesigns / gist:5217699
Created March 21, 2013 23:16
WordPress body classes
//print page and parent slugs for css classes
function page_slug_classes($classes) {
global $post;
$classes = array();
//get the slug of any parent pages
$parent_slug = basename(get_permalink($post->post_parent));
array_push($classes, $parent_slug);
//get the slug of the current page
@madysondesigns
madysondesigns / gist:5306705
Created April 4, 2013 00:29
WordPress blog check
//finally have a function to check if we're anywhere on the damned blog and only the blog
function is_blog() {
if ( get_post_type() == 'post' || is_post_type_archive( 'post' ) ) {
$blog = is_home() || is_archive() || is_single();
return $blog;
}
}
@madysondesigns
madysondesigns / gist:8560821
Created January 22, 2014 15:33
WordPress Custom Template for a Single Post ID
// Hook into the single_template filter to use a custom template for one particular
// post and still have it appear in the regular blog archives, featured posts, etc.
// Template should be named 'single-[postID].php.
add_filter('single_template', 'widget_custom_post');
function widget_custom_post($template) {
global $post;
// If it's the desired post, override the standard template with custom.
@madysondesigns
madysondesigns / gist:9982968
Created April 4, 2014 20:56
Git Cheatsheet
Checking in/out:
$ git clone [project url] - get a copy of repo in a folder
$ git checkout [file] - check out last committed version of a file
$ git add --patch [file] - Step through each section of changes in a file with option to stage or not stage
$ git remote rm origin - remove origin
$ git remote add origin [url] - add origin
Working with Branches:
$ git branch [foo] - create branch named foo
@madysondesigns
madysondesigns / aws_cf_invalidate.rb
Last active August 29, 2015 14:10 — forked from jmlacroix/aws_cf_invalidate.rb
Invalidate Cloudfront objects from the command line.
# Forked from jmlacroix/aws_cf_invalidate.rb
# Modified to read s3 creds from the environment and the distribution id from arguments passed in.
require 'rubygems'
require 'hmac-sha1'
require 'net/https'
require 'base64'
s3_access=ENV['S3_ACCESS']
s3_secret=ENV['S3_SECRET']
@madysondesigns
madysondesigns / calc_years_since.php
Created April 5, 2016 01:02
Calculate years since
function calc_years_since($year) {
$since = date("Y") - $year;
if ($since == 1) {
$since .= " year";
} else {
$since .= " years";
}
echo $since;
In functions.php:
function load_podcast_from_slug($slug) {
echo "https://soundcloud.com/graphicdesignerpodcast" . $slug;
}
In single.php inside the loop:
load_podcast_from_slug($post->post_name);