Skip to content

Instantly share code, notes, and snippets.

View natejacobson's full-sized avatar

Nathan Jacobson natejacobson

  • Discovery Institute
  • Seattle, WA
View GitHub Profile
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
* Mucker: Nate Jacobson
*
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function get_column_options() {
$column_options = array (
@natejacobson
natejacobson / equalizing.js
Last active August 29, 2015 13:56
A Column Equalizer
$(document).ready(function(){
function equalizing() {
if( $('.equalize').length ) {
$('.row.equalize .column').css('min-height','');
$('.row.equalize').each(function(){
var tallestBox = 0;
$('.column', this).each(function(){
if($(this).height() > tallestBox) {
tallestBox = $(this).outerHeight();
@natejacobson
natejacobson / pull-display-posts
Last active August 29, 2015 14:05
Display posts from WordPress JSON api
(function($){
function display_posts( data ) {
var results = data;
var i = 0;
$.each( results, function( index, value ) {
if(index<3){
console.log( value ); // Use this to see what object properties are available, like date, content, etc...
var html = '';
@natejacobson
natejacobson / wsuwp-multiple-feeds
Last active August 29, 2015 14:05
Using the Syndicate plugin of WSUWP, place multiple feeds
(function ($) {
'use strict';
function display_posts(feed, slug, element, title, count) {
if (element == 'main') {
$('main').append(
'<section class="row margin-right gutter feed json shortcode">'
+ '<div id="' + slug + '" class="column one ' + slug + '">'
+ '<h2>' + title + '</h2>'
+ '</div>'
@natejacobson
natejacobson / gist:fccf376a805c49345a2a
Created January 16, 2015 00:39
Throwing array error.
function spine_excerpt_style_classes( $classes ) {
global $post;
if ( !is_singular() ) {
if ( $post->post_excerpt ) {
$classes[] = "summary-excerpted";
} elseif ( strstr( $post->post_content, '<!--more-->' ) ) {
$classes[] = "summary-divided";
} elseif ( 'excerpt' === spine_get_option( 'archive_content_display' ) ) {
$classes[] = "summary-truncated";
@natejacobson
natejacobson / get_element_contents.php
Last active August 29, 2015 14:16
Get html or inner html for output elsewhere using php.
<?php
header("Content-Type: text/html; charset=utf-8");
function get_url_element_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
@natejacobson
natejacobson / emailer.php
Last active August 29, 2015 14:16
PHP Mailer for Sending Test HTML Emails to Multiple Clients
<?php
$url = "http://example.com/email.html";
if ( $_GET["url"] != "" ) { $url = $_GET["url"]; }
// Determine Recipients
$recipients = $_GET["to"];
$to = "default.recipient@example.com";
// Desktop Clients
if ($recipients == "mail") { $to = "mail.user@example.com"; } // Apple Mail (Gold Standard)
@natejacobson
natejacobson / wp_image_figure_wrap.js
Last active August 29, 2015 14:17
Normalize WordPress images and figures by auto wrapping images and exposing assigned image classes on figure
function imageWrap() {
$("article img").each( function() {
var img_classes = $(this).attr("class");
var img_src = $(this).attr("src");
if ( !$(this).parent().is("figure") ) {
$(this).unwrap("p").wrap('<figure class="figure-auto figure-back '+img_classes+'" style="background-image: url(\''+img_src+'\')"></figure>');
@natejacobson
natejacobson / freshness_class.php
Last active August 29, 2015 14:17
Tag posts and pages with how recent they are in WordPress
// Assign to body on single pages and to each article in lists
add_filter( 'body_class', 'post_freshness_class' );
add_filter( 'post_class', 'post_freshness_class' );
function post_freshness_class( $classes ) {
$interval = ( current_time( 'Ymd', $gmt = 0 ) - get_the_date('Ymd') );
$interval_month = ( current_time( 'Ym', $gmt = 0 ) - get_the_date('Ym') );
if ( !is_page() ) {
@natejacobson
natejacobson / section-backgrounds.js
Created June 12, 2015 21:21
Background Data to Style for WSU Spine Parent Theme
(function( $ ){
process_section_backgrounds = function() {
var $bg_sections = $('.section-wrapper-has-background');
$bg_sections.each( function() {
var background_image = $(this).data('background');
$(this).css('background-image', 'url(' + background_image + ')' );
});
};