Skip to content

Instantly share code, notes, and snippets.

View soutar's full-sized avatar
🤖
automating things

John Soutar soutar

🤖
automating things
  • Glasgow, Scotland
  • 14:20 (UTC +01:00)
View GitHub Profile
@soutar
soutar / get_ancestor.php
Created April 28, 2014 09:10
Return the ultimate ancestor of a post
<?php
/* Return the ultimate ancestor of a post */
function get_post_ancestor($postID) {
$post = get_post($postID);
if (!is_object($post)) return;
while ($post->post_parent != 0): $post = get_post($post->post_parent); endwhile;
return $post;
}
@soutar
soutar / section_nav.php
Last active August 29, 2015 14:00
Quick infinite-depth subnav for WordPress
<?php
function cad_section_nav($title = true) {
global $post;
if (!is_object($post)) return;
$section = get_post_ancestor($post->ID);
$pages = get_pages(array(
'parent' => $section->ID
@soutar
soutar / oo_shortcodes.php
Last active August 29, 2015 14:01
OO Shortcodes
<?php
class My_Shortcode extends Shortcode {
public function main($atts, $content) {
echo "This is a really easy way to add shortcodes!";
}
}
$My_Shortcode = new My_Shortcode;
$My_Shortcode->add();
@soutar
soutar / functions.php
Created May 20, 2014 12:23
Enqueue Font Awesome styles
<?php
function include_font_awesome() {
wp_enqueue_style('font_awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
}
/* When 'wp_enqueue_scripts' takes place, trigger this function */
add_action('wp_enqueue_scripts', 'include_font_awesome', 100);
@soutar
soutar / colestrap.sh
Last active August 29, 2015 14:01
Colestrap
#!/bin/bash
blue="\e[0;34m"
purple="\e[0;35m"
orange="\e[0;33m"
green="\e[0;32m"
white="\e[0;37m"
red="\e[0;31m"
echo "-------------------------------------------"
@soutar
soutar / between.less
Last active August 29, 2015 14:01
LESS: Combine mixins, bubbling and ruleset params to create more readable media queries
.branding {
display: block;
.between(@grid-float-breakpoint, @screen-md, {
display: none;
});
}
.between(@min, @max, @rules) {
@media screen and (min-width: @min) and (max-width: @max) {
@soutar
soutar / over-engineered.js
Created July 11, 2014 10:57
How to massively over-engineer a method which is possible natively with getBoundingClientRect() - A guide by someone who didn't know about getBoundingClientRect()
calculateWidthOld: function (elem) {
var tr, values, transform,
a, b,
angle, width, height,
adjustedWidth;
transform = [
elem.css('-webkit-transform'),
elem.css('-moz-transform'),
elem.css('-ms-transform'),
@soutar
soutar / related-category.php
Created July 11, 2014 12:41
"Related category" functions from a widget built for S. Collins & Son
@soutar
soutar / zip.sh
Created July 14, 2014 12:26
Zip up a project without the node_modules or git files
zip -r <project_name>.zip Site -x *.git* -x *node_modules*
@soutar
soutar / .bash_profile
Created September 17, 2014 13:15
Bash profile
# Path set for homebrew
export PATH="/usr/local/bin:$PATH"
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
alias lwj='cd /Volumes/CC\&A\ LIVE\ WEB\ JOBS/'
alias reinit='cd "`pwd`"'