Skip to content

Instantly share code, notes, and snippets.

View rbk's full-sized avatar

Richard Keller rbk

View GitHub Profile
@rbk
rbk / sidebar.php
Created July 8, 2015 18:53
Wordpress two level sidebar
<?php
$sidebar = false;
$subpages = get_posts(array('post_type'=>'page', 'post_parent'=>$post->ID));
if( count($subpages) > 0 ){
foreach( $subpages as $sp ){
if( $sp->ID == $post->ID ){
$sidebar .= '<div><a class="active" href="'.$sp->guid.'">'.$sp->post_title.'</a></div>';
} else {
$sidebar .= '<div><a href="'.$sp->guid.'">'.$sp->post_title.'</a></div>';
@rbk
rbk / functions.php
Created July 15, 2015 20:25
Rbk ToolKit - Curly brace swap
function rbkCurlySwap($shortcodes,$string) {
foreach( $shortcodes as $key => $value ){
$string = str_replace( '{{'.$key.'}}', $value, $string );
}
return $string;
}
@rbk
rbk / gist:692c5fc92e565366deb6
Created August 6, 2015 22:02
Found on stackover, WordPress image upload anywhere
<?php wp_enqueue_media(); ?>
<div>
<label for="image_url">Image</label>
<input type="text" name="image_url" id="image_url" class="regular-text">
<input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#upload-btn').click(function(e) {
@rbk
rbk / php
Created August 7, 2015 19:09
Calculate width based on max height
function rbk_calculate_image_width_based_on_max_height( $filename, $max_height ) {
if( !empty($filename) ){
$attributes = getimagesize( $filename );
$image_width = $attributes[0];
$image_height = $attributes[1];
if( $image_width > $image_height ){
return $image_width / $image_height * $max_height;
} else {
@rbk
rbk / subpage-list-widget.php
Last active August 29, 2015 14:27
Widget with option to select a parent page. The widget shows the parent with a list of subpages below.
<?php
/*
Plugin Name: Subpage List Widget
Description: A widget to list the subpages of a page.
Version: 1
Author: GuRuStu.co
Author URI: http://gurustu.co
*/
/**
@rbk
rbk / index.php
Last active February 27, 2020 18:01
Turn input placeholders into floating labels for WP Contact Form 7 fields
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
Plugin name: WPCF7 FLoating Labels
Author: Richard Keller
URI: http://richardkeller.net
Description: Adds floating lables to all text inputs
*/
@rbk
rbk / wpcf7.html
Created August 26, 2015 15:50
Notification email for WP Contact Form 7
<h1>Quote Request</h1>
<style type="text/css">
body {
font-family: arial, helvetica, sans-serif;
}
table {
table-layout: fixed;
width: 600px;
border: 1px solid #eee;
@rbk
rbk / main.js
Last active September 9, 2015 21:26
Inner grid. Grid border is never on the outside.
function set_grid_borders( ){
var grid = $('.brand-grid');
if( grid.length ){
var grid_w = grid.width();
var grid_h = grid.height();
var grid_items = grid.find('.item');
@rbk
rbk / slider-metabox.php
Created October 1, 2015 17:06
Slider metabox for links
<?php
/**
* Generated by the WordPress Meta Box generator
* at http://jeremyhixon.com/tool/wordpress-meta-box-generator/
*/
function slide_link_get_meta( $value ) {
global $post;
$field = get_post_meta( $post->ID, $value, true );
@rbk
rbk / jquery.equalize.js
Last active October 22, 2015 18:43
Equalize the heights of a set of elements
jQuery.fn.equalize = function( ){
var tallest = 0;
jQuery(this).each(function(){
if( jQuery(this).height() > tallest ){
tallest = jQuery(this).height();
}
});
if( jQuery(window).width() > 992 ){
jQuery(this).css('height',tallest + 'px');
} else {