Skip to content

Instantly share code, notes, and snippets.

View tpennock-gist's full-sized avatar

Taylor Pennock (Code Snippets) tpennock-gist

View GitHub Profile
@tpennock-gist
tpennock-gist / Wordpress Post Sorting
Created July 20, 2012 16:25
Wordpress Post Sorting for 'popular' and 'newest', captures post view count and sets it in the DB for each post (popularity factor), captures query string parameters for minor class replacements of the filter buttons (for css)
<?
// Place this code into your archive.php template file
$filter = $_GET['filter'];
// Preserve existing query parameters
global $wp_query;
// Check query string parameter "filter" (options: 'popular' and 'newest')
if((isset($filter)) && $filter == 'popular'){
$args = array_merge( $wp_query->query, array('order' => 'desc', 'orderby' => 'meta_value_num', 'meta_key' => 'post_views_count') );
@tpennock-gist
tpennock-gist / Wordpress - Display wp_query details
Created July 20, 2012 16:18
Wordpress - Display wp_query SQL query details
<? echo $GLOBALS['wp_query']->request; ?>
@tpennock-gist
tpennock-gist / is_blog.php
Created July 12, 2012 22:08 — forked from wesbos/is_blog.php
WordPress is_blog()
function is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
@tpennock-gist
tpennock-gist / appender.go
Created May 3, 2012 20:51 — forked from beatgammit/appender.go
UTOS - Introduction to Go
package main
import "fmt"
type Appender struct {
data []byte
}
func (a *Appender) Write(p []byte) (int, error) {
newArr := append(a.data, p...)
@tpennock-gist
tpennock-gist / HTML5 * Boilerplate
Created April 17, 2012 15:52
HTML5 * Boilerplate
/**
* HTML5 ✰ Boilerplate
*
* style.css contains a reset, font normalization and some base styles.
*
* Credit is left where credit is due.
* Much inspiration was taken from these projects:
* - yui.yahooapis.com/2.8.1/build/base/base.css
* - camendesign.com/design/
* - praegnanz.de/weblog/htmlcssjs-kickstart
@tpennock-gist
tpennock-gist / gist:2039068
Created March 14, 2012 19:56 — forked from padolsey/gist:527683
JavaScript: Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@tpennock-gist
tpennock-gist / gist:2039041
Created March 14, 2012 19:54
JavaScript: jQuery PubSub
(function($) {
var o = $( {} );
$.each({
on: 'subscribe',
trigger: 'publish',
off: 'unsubscribe',
}, function( key, api ) {
$[api] = function() {
o[key].apply( o, arguments );
@tpennock-gist
tpennock-gist / gist:2039015
Created March 14, 2012 19:50
CSS: Image Replacement
.ir {
border: 0;
font: 0/0 a;
text-shadow: none;
color: transparent;
background-color: transparent;
}
@tpennock-gist
tpennock-gist / gist:2038981
Created March 14, 2012 19:47
JavaScript: Sexy PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
@tpennock-gist
tpennock-gist / gist:2038925
Created March 14, 2012 19:41
HTML: Starting Template
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<body>