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 / 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 / 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 / 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: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: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 / 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: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 / 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:1f2c710b234ce65c5765
Last active March 24, 2016 10:47
WordPress sample page/post content
<h1>Heading 1</h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam et mattis nulla. Quisque volutpat arcu et accumsan tincidunt <strong>this is bold</strong>. <em>This is italic</em> Cras non lorem dui. Aenean quis erat mi. Sed metus ligula, varius quis lacinia at, rhoncus in est. Donec <a href="http://www.google.com">this is a link</a>. Fusce facilisis, nisi sed egestas euismod, tortor turpis tincidunt leo, sit amet aliquet nulla elit in nulla. Mauris dapibus varius quam eget interdum. Maecenas libero purus, egestas et interdum nec, semper in nulla. Curabitur a neque posuere, ullamcorper nibh vel, vestibulum libero. Maecenas commodo ipsum id risus euismod, ut mollis massa posuere. In eget vestibulum dolor, vel scelerisque magna. Nulla non sapien eu elit posuere hendrerit.
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<img class="alignright" src="https://placeimg.com/300/400/any" alt="" width="300" height="400" />Ut in nisl ligula. Vivamus et d
@KnightAlex
KnightAlex / gist:9cfe0da49683fe577a27
Last active August 29, 2015 14:04
Woothemes Flexslider - responsive height fix
function fixHeight() {
var maxHeight = 0,
slides = el.find('.slides'),
data = el.data('flexslider');
slides.children()
.height('auto')
.each(function() {
maxHeight = Math.max(maxHeight, $(this).height());
})
.height(maxHeight);