This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Conditional Event Handling | |
$('#target').click(function(e) { | |
if ( $(e.target).is('a') ) { | |
// code | |
// e.preventDefault(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# back to top | |
$ -> | |
$(window).scroll -> | |
if $(this).scrollTop() > 100 | |
$("#back-to-top").fadeIn() | |
else | |
$("#back-to-top").fadeOut() | |
# scroll body to 0px on click |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use as an alternative to query_posts. note: doesn't work for pages | |
add_action('pre_get_posts','wpse50761_alter_query'); | |
function wpse50761_alter_query($query){ | |
if( $query->is_main_query() ){ | |
//Do something to main query | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin keyframes($name) { | |
@-webkit-keyframes #{$name} { | |
@content; | |
} | |
@-moz-keyframes #{$name} { | |
@content; | |
} | |
@-o-keyframes #{name} { | |
@content; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stickyNav() { | |
var footer = $("footer"); | |
var pos = footer.position(); | |
var height = $(window).height(); | |
height = height - pos.top; | |
height = height - footer.height(); | |
if (height > 0) { | |
footer.css({'margin-top' : height+'px'}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try{ | |
/* Connect to Database */ | |
$dsn = 'mysql:dbname=test;host=localhost'; | |
$dbh = new PDO($dsn,'username','password'); | |
/* Create SQL String with parameters */ | |
$sql = 'SELECT name, colour, calories | |
FROM fruit | |
WHERE calories < :calories AND colour = :colour'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Set Content Encoding Header */ | |
header('Content-type: application/json; charset=utf-8'); | |
/* Array of animals*/ | |
$myArray = array( | |
array('type'=>'cat','name'=>'Alfie','age'=>2), | |
array('type'=>'dog','name'=>'Bella','age'=>6) | |
); | |
/* Encode to JSON */ | |
$jsonString = json_encode($myArray); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Set Content Encoding Header */ | |
$json = '[{"type":"cat","name":"Alfie","age":2},{"type":"dog","name":"Bella","age":6}]'; | |
/* Parse JSON to Object */ | |
$object = json_decode($json); | |
/* Parse JSON to Array */ | |
$array = json_decode($json,true); | |
/* Print Object */ | |
var_dump($object); | |
/* Print Array */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Get server time */ | |
$date = new DateTime(); | |
echo $date->format('Y-m-d H:i:s'); | |
/* Add 1 Day */ | |
$date->add(new DateInterval('P1D')); | |
echo '<br>'.$date->format('Y-m-d H:i:s'); | |
/* Change Timezone to UTC */ | |
$date->setTimezone(new DateTimeZone('etc/UTC')); | |
echo '<br>'.$date->format('Y-m-d H:i:s'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
try{ | |
$dsn = 'mysql:dbname=test;host=localhost'; | |
$dbh = new PDO($dsn,'username','password'); | |
echo 'Connected to Database'; | |
}catch (PDOException $e){ | |
echo 'Connection Failed: '.$e->getMessage(); | |
}catch(Exception $e){ | |
echo 'A Unknown Error Occurred: '.$e->getMessage(); | |
} |