Skip to content

Instantly share code, notes, and snippets.

View kingkool68's full-sized avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
@kingkool68
kingkool68 / Related WordPress Posts
Last active January 8, 2016 18:20
This plugin features a smarty-pants set of functions to determine what content is related to what.
@kingkool68
kingkool68 / cleverroot-infinite-scroll.js
Last active January 19, 2016 04:30
Infinite Scroll for CleverRoot
jQuery(document).ready(function($) {
//Set-up some constants.
var scrollTimeout;
var scrollUsePushStateInstead = false; //Set to true to make the history stack of the browser include every point when posts were loaded. It's kind of annoying.
var scrollDelay = 200; //Milliseconds
var scrollLoading = false;
var triggerOffset = $(document).height() - $('article').eq(-4).offset().top; //The point of this is to do one calculation up front instead of multiple calculations every time the infinite scroll is triggered.
// Simple feature detection for History Management (borrowed from Modernizr)
function supportsHistory() {
@kingkool68
kingkool68 / goddard_breadbrumbs.php
Created February 16, 2016 19:59
An example of how to write your own breadcrumbs function in WordPress
function goddard_breadcrumbs( $post_id = FALSE ) {
global $post;
if( $post_id ) {
$post = get_post( $post_id );
}
if( !$post && !is_404() && !is_search() ) {
return false;
}
$crumbs = array(
@kingkool68
kingkool68 / rh-404-overrides.php
Created February 26, 2016 21:17
Use the GUID field to maintain old URL redirects
<?php
function rh_404_overrides() {
global $wp_query, $wpdb;
if( $wp_query->is_404 && isset( $wp_query->query_vars['pagename'] ) && !empty( $wp_query->query_vars['pagename'] ) ) {
$query = "SELECT `ID` FROM `" . $wpdb->posts . "` WHERE `guid` LIKE '%" . $wp_query->query_vars['pagename'] . "%' LIMIT 0,1;";
$post_id = intval( $wpdb->get_var( $query ) );
if( $url = get_permalink( $post_id ) ) {
wp_redirect( $url, 301 );
@kingkool68
kingkool68 / gulp.js
Last active March 7, 2016 19:06
Using filenames as variables in gulp.js
var gulp = require('gulp');
var del = require('del');
gulp.task('clean:min-css', function () {
// Delete all *.min.css files in the CSS directory so we don't get duplicates
return del([
'css/*.min.css'
]);
});
@kingkool68
kingkool68 / changelog.sh
Last active September 17, 2023 21:08
Bash script to generate a markdown change log of GitHub pull requests between tagged releases
#!/bin/bash
# Generate a Markdown change log of pull requests from commits between two tags
# Author: Russell Heimlich
# URL: https://gist.github.com/kingkool68/09a201a35c83e43af08fcbacee5c315a
# HOW TO USE
# Copy this script to a directory under Git version control
# Make the script executable i.e. chmod +x changelog.sh
# Run it! ./changelog.sh
# Check CHANGELOG.md to see your results
@kingkool68
kingkool68 / composer.json
Created September 5, 2016 19:24
Sample composer.json for managing plugins via Composer
{
"name": "your-github-name/your-repo",
"license": "GPLv3",
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Your Name",
"email": "your@email.com"
},
@kingkool68
kingkool68 / tally-email-subscribers-via-slack
Created September 21, 2016 21:28
PHP Script to Parse Slack Messages and Tally Data from Bots
<?php
/**
* This script will parse our Slack history and pull email subscriber counts that were posted by our bots.
* Place in the root of a WordPress install, add a Slack token for API access, and visit the URL
*
* A CSV file of the results will be downloaded.
* For further analys import into a database (See Below)
*
*/
<?php
include 'simple_html_dom.php';
$html = file_get_html('http://www.asia.si.edu/exhibitions/past.asp');
$output = array();
foreach( $html->find( '#filterarea li' ) as $elem ) {
$h1 = $elem->find( 'h1', 0 );
if ( $h1 ) {
continue;
}
@kingkool68
kingkool68 / example.php
Created November 22, 2016 02:39
Grouping the results of a WordPress loop by month and year
<?php
$args = array(...);
$my_posts = new WP_Query( $args );
$the_year = '';
$the_month = '';
if ( $my_posts->have_posts() ) :
while ( $my_posts->have_posts() ) :
$my_posts->the_post();
// Get the year of the post in YYYY format
$post_year = get_the_time( 'Y' );