Skip to content

Instantly share code, notes, and snippets.

@ianshea
ianshea / states-select.html
Created August 1, 2013 21:54
States/Provinces Select
<select id="state" name="state">
<option></option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
@ianshea
ianshea / .htaccess
Created October 8, 2013 14:54
GoDaddy CraftCMS .htaccess
AddHandler x-httpd-php5-3 .php
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
@ianshea
ianshea / craft.conf
Last active December 25, 2015 18:19 — forked from kenzie/craft.conf
server {
listen 80;
root /var/www/craft.dev/public;
index index.php index.html index.htm;
server_name craft.dev;
location / {
try_files $uri $uri/ @rewrites;
@ianshea
ianshea / serializeObject
Created November 21, 2013 03:24
$.fn.serializeObject
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
@ianshea
ianshea / Sublime Text Packages
Created December 30, 2013 16:48
Sublime Text
## Packages
- [Emmet](http://emmet.io)
- [AdvancedNewFile](https://github.com/skuroda/Sublime-AdvancedNewFile)
- [GitGutter](https://sublime.wbond.net/packages/GitGutter)
## Syntax
- [Sass](https://sublime.wbond.net/packages/Sass)
@ianshea
ianshea / gist:8340502
Created January 9, 2014 19:37
Update Node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
@ianshea
ianshea / button.js
Last active January 3, 2016 13:09
Paginated JSON for Craft Example
// requires underscore.js, jquery
$('.load-more-btn').on('click', function( e ){
{
var $this = $(e.currentTarget);
// Precompile Template for loaded items
var tmpl = _.template( $('#tmpl-workitem').html() );
// Run Ajax Request for next page of items
@ianshea
ianshea / global-navigation.twig
Created March 14, 2014 21:19
Craft/Twig/Dry Structure Question
<nav>
{# Really need to poke around and find a better way to do this. Seems rather database expensive. #}
{% set ourTribe = craft.entries.section('ourTribe').depth(1) %}
{% set ourTribeId = ourTribe.first().section %}
{% set camasCenter = craft.entries.section('camasCenter').depth(1) %}
{% set camasCenterId = camasCenter.first().section %}
@ianshea
ianshea / gist:0aed51a1f4845d055ff6
Last active August 29, 2015 14:04
CraftCMS Range of Events
{#
I'm using this to build out a calendar. Not every month/day on the calendar has an event and I don't want a user to go into May 2034 and see nothing.
I needed a way to go from the current day and count out to the last event in the database and show everything in between. This is what I ended up doing.
This method assumes you have a channel of events.
Every event is assigned to an 'event' category with sub categories below it.
Every entry has an 'eventTime' date field within it.
I'm not worrying about recurring events. It's unneeded for this application.
#}
@ianshea
ianshea / firsts
Created July 16, 2014 18:47
First Entry from First Sub Category from Top Category Slug in Craft
{# Get the category from the slug. This will return one CategoryModel #}
{% set topCat = craft.categories.slug('someSlug').first() %}
{# Get the first subcategory under the top level category using the getChildren() method on the category model. #}
{% set firstSubCat = topCat.getChildren().first() %}
{# Grab the first entry under that category using the relatedTo function and appending the .first() method to return only one item. #}
{% set firstEntry = craft.entries.relatedTo( firstSubCat ).first() %}
{# Set your image from your asset field #}