Skip to content

Instantly share code, notes, and snippets.

View tomjn's full-sized avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
@tomjn
tomjn / gist:6140172
Last active December 20, 2015 13:39
If you're lucky enought o be running WordPress on PHP 5.5, you can use generators for your post loops like this
<?php
// with the above we can now do things like this:
foreach ( posts_loop() as $p ) {
get_template_part( 'content', 'page' );
comments_template( '', true );
}
// put this below in your functions.php:
@tomjn
tomjn / helloworld.php
Last active July 3, 2018 11:50
An example of how to use the class defined here: https://gist.github.com/Tarendai/6089867
<?php
require_once( 'custom_page.php' );
class Hello_World_Page extends Tomjn_Custom_Page {
public function render_page() {
echo 'hello world!';
}
}
@tomjn
tomjn / custom_page.php
Last active July 3, 2018 11:50
A base class used to create arbitrary content at arbitrary URLs in WordPress without needing a post or listing/archive to host it
<?php
/**
* A helper class to implement arbitrary content at arbitrary URLs without a supporting post or page.
* Inherit from this class and implement the render_page method
*
* @author: Tom J Nowell ww.tomjn.com
* @License: GPL 2+
*/
abstract class Tomjn_Custom_Page {
@tomjn
tomjn / treechop.lua
Created May 27, 2013 14:32
Computercraft tree farm chops down and grows a tree given saplings and bonemeal, place a chest underneath
local slots ={}
function plantTree()
turtle.select(1)
turtle.place()
end
function chopTree()
turtle.select(4)
turtle.dig()
@tomjn
tomjn / texcavate.lua
Last active December 17, 2015 11:49
Computercraft excavate that digs 2 levels at a time, working on a third
--[[
TExcavate by Tom J Nowell
A modified version of the excavate command, mines 3 layers of rock at a time, and keeps persistent variables
requires: http://www.computercraft.info/forums2/index.php?/topic/1195-132-yet-another-persistent-variables-api-uses-metatable/
]]--
os.loadAPI("apis/persistentVar") -- Only use this line if you copied the API in your computers apis folder
local state = persistentVar:new( "/vars_texcavate/" )
@tomjn
tomjn / auditor-twitter-followers.php
Last active December 16, 2015 22:49
A plugin that extends the auditor to track who in the Interconnect/IT offices has the most twitter users
<?php
/*
Plugin Name: Twitter Follower Audit Tracker
Plugin URI: http://interconnectit.com/products/the-auditor/
Description: Uses the auditor to track twitter follower counts, requires v1.63+
Author: Tom J Nowell, interconnect/it
Version: 1.1
Author URI: http://interconnectit.com
*/
@tomjn
tomjn / shortcode.php
Last active December 16, 2015 09:09 — forked from r-a-y/shortcode.php
Always ommit trailing php close tags, indent correctly, and remove the IDE unfriendly shorthand
<?php
if ( ! function_exists( 'shortcode_exists' ) ) {
/**
* Check if a shortcode is registered in WordPress.
*
* Examples: shortcode_exists( 'caption' ) - will return true.
* shortcode_exists( 'blah' ) - will return false.
*/
function shortcode_exists( $shortcode = false ) {
global $shortcode_tags;
Have you tried using git to do that?
@tomjn
tomjn / gist:5151718
Created March 13, 2013 12:42
Change the local indicator colour
<?php
function indicator_colour( $indicator_colour ) {
return 'yellow';
}
add_action( 'tomjn_indicator_colour', 'indicator_colour' );
@tomjn
tomjn / gist:5151708
Created March 13, 2013 12:41
Change the text of the local indicator
<?php
function indicator_helloworld( $indicator_text ) {
return 'Hello World!!!';
}
add_action( 'tomjn_indicator_text', 'indicator_helloworld' );