Skip to content

Instantly share code, notes, and snippets.

View martynchamberlin's full-sized avatar

Martyn Chamberlin martynchamberlin

View GitHub Profile
@martynchamberlin
martynchamberlin / gist:4515705
Last active December 11, 2015 00:19
In C#, all constructors in polymorphism will fire, starting at the top of the tree and working down. Sometimes this isn't the desired behavior. Here's a potential workaround using a simple Window Console application.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
B myObj = new B();
// comment the next line to disable parent constructor
myObj.Initialize();
}
@martynchamberlin
martynchamberlin / gist:5278521
Last active December 15, 2015 14:59
Force SSL on WordPress Pages, in this case, a page with an ID of 2
<?php
$using_ssl = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443;
add_action('wp', 'check_ssl');
function check_ssl()
{
// Page ID 2 must be https
if (is_page(2) && !$using_ssl)
{
header('HTTP/1.1 301 Moved Permanently');
@martynchamberlin
martynchamberlin / sticky_footer.js
Last active December 17, 2015 19:19
Sticky footer using jQiery
@martynchamberlin
martynchamberlin / app.php
Created June 8, 2013 20:57
Code for moving subscribers from one list to another in AWeber.
<?php session_start(); ?>
<form action="" method="post">
<div>
<label>Old list name</label>
<input type="text" name="list_name" <?php if (isset($_SESSION['list_name'] )) echo 'value="' . $_SESSION['list_name'] . '"'; ?>
</div>
<div>
<label>New list name</label>
@martynchamberlin
martynchamberlin / demo.js
Last active December 20, 2015 08:39
Super easy way to give similar items a unique DOM identifier using jQuery
jQuery(document).ready(function( $ )
{
var i = 1;
$('nav li').each(function()
{
$(this).addClass('item_' + i );
i++;
});
});
@martynchamberlin
martynchamberlin / functions.php
Last active December 20, 2015 23:29
Shortcode for retrieving URL variables within WordPress
<?php
/**
* Insert this code inside your functions.php file. Do not have the opening <?php tag, as this should
* already exist at the top of your functions file.
*
* USAGE: If you have firstname as a variable in your page's URL (e.g. http://mydomain.com?firstname=Martyn)
* then putting [get var=firstname] into a WordPress post type or widget would print "Martyn" to the screen.
* After using exec PHP plugins for months (i.e. <?php echo $_GET['firstname']; ?>) I'm moving away from
* executing PHP directly in posts/pages and widegets. This is the whole reason shortcodes were invented in the
@martynchamberlin
martynchamberlin / functions.php
Last active February 16, 2018 00:09
How to get_the_content() with formatting
<?php
/**
* Instead of calling get_the_content(), call this function instead, and it'll all be good
*/
function get_the_content_with_formatting()
{
ob_start();
the_content();
$the_content = ob_get_contents();
@martynchamberlin
martynchamberlin / quotes-collection.php
Last active December 21, 2015 05:49
Getting truly unique quotes with Srini G's Quotes Collection plugin for WordPress
<?php
/**
* The Quotes Collection plugin, downloadable at http://wordpress.org/plugins/quotes-collection/,
* is a great plugin. I've used it on a couple of client sites and it's simple to use.
* However, there exists one little problem. If you want to show more than one quote
* on a page, and you want those quotes to be different every time, there's no way to do
* that. Replace the quotescollection_get_quote() function in quotes-collection.php with
* my modified version below. Specifically, this guarantees that the quotes are truly random,
* and that once served on a page, you will not get the same quote again. To prove this in
@martynchamberlin
martynchamberlin / demo.html
Created August 28, 2013 21:36
If we still lived in the 1990s, this would be the best way to create a navigation that changed on hover. This Javascript is compatible with IE 5.5, which is such an old browser that a:hover is meaningless to it. So, how does this work? Well, if you have an image named "btn-1.png" and you give it a "name" property of "btn-1", you can create an im…
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>1990s navigation (!)</title>
</head>
<body>
<script type="text/javascript" language="javascript">
function toggle( resource ) {
@martynchamberlin
martynchamberlin / functions.php
Last active December 23, 2015 00:59
I highly recommend the Query Multiple Taxonomies (http://scribu.net/wordpress/query-multiple-taxonomies/) plugin. It lets you build custom post types and custom taxonomies. But what if you are in a WordPress post type and want to print that a taxonomy of that post to the screen? "Stupid idea!" You say. "I specify that post's taxonomies within th…
<?php
function z_get_taxonomy( $var )
{
extract( shortcode_atts( array(
'name' => ''
), $var ) );
$postID = get_the_ID();
if ( ! empty( $name ) )
{