Skip to content

Instantly share code, notes, and snippets.

@bencooling
bencooling / Less functions
Created December 28, 2011 01:15
Helpful Less functions provided by Joni Korpi
.box-shadow (@string) {
-webkit-box-shadow: @string;
-moz-box-shadow: @string;
box-shadow: @string;
}
.border-radius (@radius: 2px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
@bencooling
bencooling / CSS orientation classes
Created January 4, 2012 01:48
Adding specific classes based on orientation for mobile devices
<!DOCTYPE html>
<html>
<!-- http://www.ajaxbestiary.com/2011/12/19/css-and-mobile-device-orientation/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+AjaxBestiary+%28Ajax+Bestiary%29 -->
<!-- @see bcooling.com.au/testbed/orientation.html-->
<head>
<style>
html, body {
height:100%; min-height:100%; margin:0; padding:0;
}
.landscape, .portrait {
@bencooling
bencooling / Wordpress Loops
Last active September 22, 2018 22:18
Wordpress: Code for different types of Wordpress loops
<?php /* Main loop ------------------------------------------*/ ?>
<?php if (have_posts()) while (have_posts()): the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php // get_template_part( 'content', 'home' ); ?>
<?php endwhile; ?>
<?php /* Simple alter main loop ------------------------------------------*/ ?>
<?php query_posts('posts_per_page=1&post_type=locations'); ?>
@bencooling
bencooling / Wordpress Privilege Author Media
Last active August 9, 2017 08:38
Prevent Authors from seeing other authors media files
// Prevent Authors from seeing other authors media files
add_filter('parse_query', 'my_parse_query' );
function my_parse_query( $wp_query ) {
// Only applicable for Media Library && Media Upload Dialog
if (! preg_match('/wp-admin\/(?:upload|media-upload|admin-ajax).php/', $_SERVER['REQUEST_URI']) ) {
return;
}
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
@bencooling
bencooling / confs.sh
Last active October 12, 2015 17:58
Keep config files open in common sublime window
#!/bin/bash
# Shell script to open various conf files related to developing for the web
# Make sure no space after \ or infinite loop of sublime text opening will occur
#--------------------------------------------------------
subl -n \
/etc/hosts \
/etc/apache2/httpd.conf \
/etc/apache2/extra/httpd-vhosts.conf \
/Users/dnadigital/.bash_profile \
/Users/dnadigital/bin/confs \
@bencooling
bencooling / .bash_profile
Last active October 12, 2015 17:58
Bash: mac osx configuration files
# Ben Cooling's mac osx bash profile
#---------------------------------
# Environment Variables
#---------------------------------
export PS1="\h \w:"
export NOW=$(date +"%Y-%m-%d")
export EDITOR="subl -w"
@bencooling
bencooling / jQuery4DaConsole
Created December 17, 2012 00:19
jQuery4DaConsole. Used in blog post for bcooling.com.au.
javascript:(function(){ var el= document.createElement("script"); el.src= 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'; document.head.insertBefore(el, document.head.firstChild); })()
@bencooling
bencooling / Teaser
Created December 17, 2012 04:07
Wordpress excerpt (teaser) snippets
/* Replace the_content() more text with a template part
------------------------------------------------------------------------------------*/
add_filter( 'the_content_more_link', 'my_the_content_more_link', 10, 2 );
function my_the_content_more_link( $more_link, $more_link_text ) {
return load_template_part('general', 'specific'); // loads general-specific.php, uses custom function load_template_part
}
// Get template partial as variable
function load_template_part($template_name, $part_name=null) {
ob_start();
get_template_part($template_name, $part_name);
@bencooling
bencooling / Wordpress Taxonomy
Created December 18, 2012 00:11
Wordpress Taxonomy related snippets
/* List child categories
---------------------------------------------------------------------------------------------------------*/
<?php
$args = array('parent' => get_query_var('cat'), 'hide_empty' => false);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>'; }
?>
@bencooling
bencooling / jQuery plugin
Last active December 10, 2015 20:58
Blank template of jQuery plugin
/*
* jQuery plugin boilerplate
* By Ben Cooling
* 2013
*
* Description:
* Internal operations available as public api
* Construct & Deconstruct methods
* Working with Ajax responses as promise objects
*