Skip to content

Instantly share code, notes, and snippets.

View astockwell's full-sized avatar

Alex Stockwell astockwell

View GitHub Profile
<?php
/*
* Reference
*
* Term object keys:
* [term_id, name, slug, term_group, term_taxonomy_id, taxonomy, description, parent]
*
*/
@astockwell
astockwell / functions.php
Last active August 29, 2015 14:01
Better way to get Wordpress post featured image
<?php
/**
* Get everything you could ever want about a featured image
*
* Usage:
* <?php $image = get_featured_image(); ?>
* <img class="thumbnail" src="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>">
*
* @param integer|object $post_id The ID/Object of the post that has the desired post thumbnail image
* @return false|array Null on failure to find the image, wp_prepare_attachment_for_js array on success
@astockwell
astockwell / Vagrantfile
Created July 20, 2014 16:58
Vagrantfile to extract data table from Microsoft Access to CSV
# -*- mode: ruby -*-
$script = <<SCRIPT
apt-get update
apt-get install -q -y wget make libtool automake autoconf bison flex unixodbc git mdbtools
cd /vagrant
echo "Get a copy of the MDB file and run 'vagrant ssh -c 'mdb-export /vagrant/database.mdb table_name > /vagrant/table_name.csv''"
SCRIPT
Vagrant.configure("2") do |config|
@astockwell
astockwell / page.php
Last active August 29, 2015 14:06
Advanced Custom Fields Pristine Field Uses
<!-- Text Field -->
<?php $field_name_slug = get_field("field_name_slug"); if ( !empty($field_name_slug) ): ?>
<?php echo $field_name_slug; ?>
<?php endif; ?>
<!-- Image Field -->
<?php $image_field_name = get_field("image_field_name"); if ( $image_field_name ): ?>
<img src="<?php echo $image_field_name["url"]; ?>" alt="<?php echo $image_field_name["title"]; ?>" />
<?php endif; ?>
@astockwell
astockwell / sortStrings.js
Last active August 29, 2015 14:17
Sort array of string numbers correctly
// JsFiddle: http://jsfiddle.net/astockwell/6jxLeppm/4/
// Array.prototype.filter polyfill for <= IE8
if (!Array.prototype.filter) {Array.prototype.filter = function(fun/*, thisArg*/) {if (this === void 0 || this === null) {throw new TypeError(); } var t = Object(this); var len = t.length >>> 0; if (typeof fun !== 'function') {throw new TypeError(); } var res = []; var thisArg = arguments.length >= 2 ? arguments[1] : void 0; for (var i = 0; i < len; i++) {if (i in t) {var val = t[i]; if (fun.call(thisArg, val, i, t)) {res.push(val); } } } return res; }; }
var containsNoNumbers = function(s) {
return s.indexOf('0') === -1;
};
var containsNumbers = function(s) {
return !containsNoNumbers(s);
@astockwell
astockwell / gist:4157590
Created November 27, 2012 22:28
SASS Mixin: Background color alpha compatible with IE 6-9
@import "compass/css3/images";
// Partially via http://www.colorzilla.com/gradient-editor/
@mixin nav-child-bg-color-alpha($color, $alpha: 0.5) {
background: url(screen.css); // Point to this css file. Fix for IE "No Transparency Click" bug on <a> elements w/ bg transparency. Via http://haslayout.net/css/No-Transparency-Click-Bug
@include background-image(linear-gradient(top, rgba($color, $alpha) 0%,rgba($color, $alpha) 100%));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{ie-hex-str(rgba($color, $alpha))}', endColorstr='#{ie-hex-str(rgba($color, $alpha))}',GradientType=0 ); /* IE6-9 */
}
// USEAGE:
@astockwell
astockwell / gist:4177665
Created November 30, 2012 18:44
Wordpress: Google Analytics with "One wp-config.php file to rule them all"
<?php if (WP_ENV != 'local' && WP_ENV != 'staging') { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
@astockwell
astockwell / script.js
Last active October 13, 2015 15:28
Detect if element exists on page in jQuery
if ($('.lt-ie8').is('*')) {
//code
}
@astockwell
astockwell / search.php
Created January 4, 2013 21:34
Google Custom Search v2 Include Code for Wordpress - WORKING
<?php get_header(); ?>
<section>
<!-- Put the following javascript before the closing </head> tag. -->
<script>
(function() {
var cx = '000000000000000000000:aaa1aa1aa1a';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
@astockwell
astockwell / loop.php
Last active December 14, 2015 11:38
Pristine Wordpress loop examples
<?php // Referencing http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts ?>
<?php
// EXAMPLE new WP_Query object
?>
<?php
// Query posts by new criteria.
$args = array(
'posts_per_page' => -1,