Skip to content

Instantly share code, notes, and snippets.

View KnightAlex's full-sized avatar

Alex Knight KnightAlex

  • Devon, United Kingdom
View GitHub Profile
@KnightAlex
KnightAlex / WP comments styling
Last active August 29, 2015 14:05
WordPress - basic comments styling
/* --- comments --- */
.commentlist {
margin-left: 0;
}
#comments {
padding-top: 20px;
}
@KnightAlex
KnightAlex / gist:b12d27b55d54745a777d
Created August 25, 2014 09:46
Reverse a list with jQuery
var list = $('ul');
var listItems = list.children('li');
list.append(listItems.get().reverse());
@KnightAlex
KnightAlex / WordPress menu walker
Created September 11, 2014 10:51
WordPress menu walker - to show menu descriptions but could be adapted to do other stuff.
// menu description walker
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
@KnightAlex
KnightAlex / gist:6ef4ff6754771de2a7dc
Last active August 29, 2015 14:06
Detect device rotation and reload page
// RELOADS WEBPAGE WHEN MOBILE ORIENTATION CHANGES
window.onorientationchange = function() {
var orientation = window.orientation;
switch(orientation) {
case 0: window.location.reload();
break;
case 90: window.location.reload();
break;
case -90: window.location.reload();
break;
@KnightAlex
KnightAlex / gist:7661bd5bd36c5c158438
Created October 7, 2014 10:02
PHP: Determine whether an object field matches needle.
<?php
$arr = array( new stdClass(), new stdClass() );
$arr[0]->colour = 'red';
$arr[1]->colour = 'green';
$arr[1]->state = 'enabled';
if (in_array_field('red', 'colour', $arr))
echo 'Item exists with colour red.';
if (in_array_field('magenta', 'colour', $arr))
@KnightAlex
KnightAlex / gist:513bf64501a3bf16d70b
Created October 9, 2014 08:59
WooCommerce get category Id from cat page
<?php
$category = get_queried_object();
echo $category->term_id;
?>
@KnightAlex
KnightAlex / gist:ebfb68cee0bc005d1892
Created October 22, 2014 17:58
WordPress: Toolset views - check if field is empty
[wpv-if fieldname="wpcf-fieldname" evaluate="empty(fieldname)" condition="false"][/wpv-if]
@KnightAlex
KnightAlex / compare arrays
Created November 4, 2014 08:38
Find one arrays items in another array
function compareArrays(sup, sub) {
sup.sort();
sub.sort();
var i, j;
for (i=0,j=0; i<sup.length && j<sub.length;) {
if (sup[i] < sub[j]) {
++i;
} else if (sup[i] == sub[j]) {
++i; ++j;
} else {
@KnightAlex
KnightAlex / Placeholder text colour
Created November 5, 2014 15:22
Placeholder text colour
::-webkit-input-placeholder {
color: red;
}
:-moz-placeholder { /* Firefox 18- */
color: red;
}
::-moz-placeholder { /* Firefox 19+ */
color: red;
@KnightAlex
KnightAlex / gist:4fc8e575d82529a19dab
Last active August 29, 2015 14:10
Remove iOS/webkit rounded corner nastiness. CSS
-webkit-appearance: none;
border-radius: 0;
-webkit-border-radius: 0;