Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View wkw's full-sized avatar

Wayne K. Walrath wkw

View GitHub Profile
@wkw
wkw / gist:2556525
Created April 30, 2012 08:22 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@wkw
wkw / jqm-config.mods.js
Created August 16, 2012 12:05
jQueryMobile and Backbone.js
// see: http://coenraets.org/blog/2012/03/using-backbone-js-with-jquery-mobile/
// for context.
// this modifies original code (above) to also watch for dialogs being hidden
$('div[data-role="page"],div[data-role="dialog"]').live('pagehide', function (event, ui) {
$(event.currentTarget).remove();
});
// HELPER: #key_value
//
// Usage: {{#key_value obj}} Key: {{key}} // Value: {{value}} {{/key_value}}
//
// Iterate over an object, setting 'key' and 'value' for each property in
// the object.
Handlebars.registerHelper("key_value", function(obj, fn) {
var buffer = "",
key;
@wkw
wkw / CalendarHelper.class.php
Last active April 27, 2022 15:46 — forked from pamelafox-coursera/CalendarHelper.class.php
Added parameter for naming calendar.ics download (optionally).
<?php
/**
* https://gist.github.com/wkw/5752757
* forked from pamelafox-coursera (https://gist.github.com/pamelafox-coursera)
*
*/
class CalendarEvent {
/**
*
<?php
/*
/* enter your Twitter username here */
DEFINE('TWITTER_USERNAME', 'replace-me');
/*
/* this is where you put in all of your secret spices */
/* check out this guide for an explaination: http://stackoverflow.com/questions/12916539/simplest-php-example-retrieving-user-timeline-with-twitter-api-version-1-1/15314662#15314662 */
@wkw
wkw / jqChangeElementType.js
Last active May 30, 2020 05:04
jQuery Change Element Type usage: $("span").changeElementType("div")
// from Andrew Whitaker and Jazzbo, http://stackoverflow.com/a/15554920/161625
$.fn.changeElementType = function(newType) {
var newElements = [];
$(this).each(function() {
var attrs = {};
$.each(this.attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.nodeValue;
});
@wkw
wkw / Wordpress Columnize Posts PHP
Last active December 28, 2015 19:19
Straightforward way to layout Wordpress posts in columns. The example is using Bootstrap styles, but it easily adapts to HTML tables, or any other markup.
/**
* utility to check if more posts available in the loop, avoiding side-effects
* mentioned in the "Note" on this page: http://codex.wordpress.org/Function_Reference/have_posts
* if more are available, it will advance the internal counter by calling the_post()
* -- this function goes in functions.php or (RootsTheme: lib/custom.php)
*/
if( !function_exists('more_posts') ){
function more_posts() {
global $wp_query;
$hasPostsLeft = $wp_query->current_post + 1 < $wp_query->post_count;
@wkw
wkw / cfs_map_values_updated
Created May 5, 2014 17:57
Synchronize Wordpress Custom Meta Fields for Custom Field Suite. This will not work if your field group(s) use loop or relationship fields.
// source: https://uproot.us/forums/questions/1511/importing-data
/*
* ============================== EXPERIMENTAL CUSTOM FIELDS SUITE FIELD SYNC ============================
*
* Importing posts with custom fields even when their names match those in CFS groups. still doesn't make
* them visible to CFS. The map_fields_values below is from a forum post on uproot's site:
* https://uproot.us/forums/questions/1511/importing-data
*
* I have hard-coded the group ID for staff_bios into _sync_cfs_fields(). Call this function after
* import.
@wkw
wkw / sitepress.class.php-bug-amelioration.php
Last active August 29, 2015 14:01
WPML Language Switcher Bug Workaround
//
// referencing v3.1.5 of WPML sitepress plugin
// in file: sitepress-multilingual-cms/sitepress.class.php
// at or near line: 5898 (inside method `convert_url`)
//
Add these three lines of code after the first larger if/block.
if ( is_null( $code ) ) {
$code = $default_language;
@wkw
wkw / WordPress On-Demand Custom Image Sizes
Created August 7, 2014 16:18
Add this to your WordPress functions.php if you are using many custom image sizes (add_image_size(...)) to prevent the creation of all the sizes upon image upload. This will only generate a custom size the first time it is requested.
/* ======================================================================================
//! -- On Demand Image Sizing --
Experimental code for generating custom image sizes on demand.
http://wordpress.stackexchange.com/a/124790
From the author...
"When an image is then requested in a particular size,
which is not yet generated, it will be created only that once."
====================================================================================== */