Skip to content

Instantly share code, notes, and snippets.

View jonesch's full-sized avatar

Christopher W. Jones jonesch

View GitHub Profile
@jonesch
jonesch / breadcrumbs-wp-postpage
Created September 10, 2012 16:48
Wordpress Breadcrumb Trail - Pages & Post
<?php // Let's make a trail of crumbs, whether we are on the post or the page....This DOES NOT support custom Post Types...
//Create an is_blog function
function is_blog($post) {
$posttype = get_post_type($post);
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
$bread_crumb_trail = '<span><a href="'.get_bloginfo('url').'">Home</a></span> &raquo;';
//Ancestors will only live on hierarchical posts...just pages.
//jQuery on Event
$('.dynamic_content_area').on('click', '.back-button', function(){
property_id = '';
loadNewContent('multi', current_page, sorting_location, sorting_area);
$('.dynamic_pagination').fadeIn(500);
});
@jonesch
jonesch / wp-login-button
Created October 4, 2012 15:11
Wordpress Login Button - SASS & Compass Style
//Set your two colors for the button
$main-green: #88a904;
$dark-green: #6b8a02;
//Overwrite the default Blue WP Login button
#wp-submit {
background-color: $main-green;
@include background-image(linear-gradient($main-green, $dark-green));
border: 1px solid $dark-green;
border-bottom: 1px solid darken($dark-green, 5%);
@jonesch
jonesch / menu-array-loop
Created October 5, 2012 15:55
Loop through an array of menu items.
//Use CSS to make these columns responsive.
<ul class="food-menus<?=(' '.$menu_category)?>">
<?php
//Let's get a count of how many items we are going to display of our menu
$total_menu_categories = count($menu[$menu_category]);
$total_items = $total_menu_categories;
foreach($menu[$menu_category] as $section => $value) {
$total_items = $total_items + count($value);
} //get the total number of <li>s on our page
$number_of_columns = 3;
@jonesch
jonesch / exact-target-curl
Created October 5, 2012 18:54
Submitting to Exact Target with cURL
<?php //I am using this for an AJAX call, and checking my responses against the success or failure that it is echoing back.
//create array of data to be posted
$full_name = stripslashes(trim(strip_tags($_POST['full_name'])));
$email_address = stripslashes(trim(strip_tags($_POST['email_address'])));
if(!empty($full_name) && !empty($email_address)){
$post_data['MID'] = "10488043";
$post_data['Full Name'] = $full_name;
$post_data['Email Address'] = $email_address;
$post_data['thx'] = '';
@jonesch
jonesch / child-sidebar-menu-wordpress
Created October 11, 2012 14:01
Custom Sidebar Menu for Children - Wordpress
//Create a custom sidebar piece that displays the pages/menus for us
function create_sidebar_menu_pages($current_id, $parent_id, $children_pages = null){
$output = '';
$output .= '<h3>';
if(empty($children_pages)){
$output .= 'Other Useful Links';
} else {
$output .= '<a href="'.get_permalink($current_id).'">'.get_the_title($parent_id).'</a>';
}
$output .= '</h3>';
@jonesch
jonesch / mailchimp-curl
Created October 18, 2012 11:45
Get List ID & Submit Email/Subscriber to MailChimp via cURL
<?php
$api_key = 'API KEY';
$prefix = 'usX'; //at the end of your API Key, there is a -us1, or us2, etc......you want the prefix to be the us2 for examples.
//Let's go Get a LIST ID for the subscriber list we are going to be putting content in.
$get_lists = 'http://'.$prefix.'.api.mailchimp.com/1.3/?method=lists';
$data = array();
$data['apikey'] = $api_key;
@jonesch
jonesch / Output An Even Number
Created October 19, 2012 20:57
PHP to always return an even number
$num = (round((count($orig_num) / 2), 0, PHP_ROUND_HALF_EVEN) * 2);
@jonesch
jonesch / mail-attachment-wordpress
Created October 22, 2012 12:40
Attaching & Validating A File. Wordpress
if(!empty($_FILES['resume']['name'])){ // check to see if we have a photo and a user clicks submit
$accept_file_formats = array(
'image/jpg',
'image/jpeg',
'image/png',
'image/gif',
'text/rtf', //.rtf file
'text/plain', //.txt file
'application/msword', //.doc file
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', //.docx file
@jonesch
jonesch / htaccess - mobile redirects
Created November 2, 2012 12:39
Catswhocode - Mobile .htaccess redirects
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/m/.*$
RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]