Skip to content

Instantly share code, notes, and snippets.

View andykillen's full-sized avatar

Andrew Killen andykillen

View GitHub Profile
@andykillen
andykillen / standard-loop-get-latest-posts.php
Last active August 16, 2016 06:42
Standard WordPress loop
<?php
$id = false;
// get current post id if a single (post or page)
if(is_single()){
global $post;
$id = $post->ID;
}
// setup basic loop arguments
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '5'
'no_found_rows' => true, // turn off pagination information
'update_post_meta_cache' => false // don't do anything with post meta cache
);
$ids = array();
// get current post id if a single (post or page)
if(is_single()){
global $post;
$ids[] = $post->ID;
}
// setup basic loop arguments
$args = array(
'post_type' => 'post',
@andykillen
andykillen / use-js-objects-for-performance.js
Last active June 18, 2016 14:10
Its gives better performance to use a javascript object than it does to use a jQuery selector.
var el = document.getElementById('header'); // this is for #header not <header>
$(el).('.some-class-used-in-header').each(function(index){
// do something!! to each of the things with this class
});
$(el.getElementsByTagName('nav')).on('touchstart click', 'a', function(e){
// do something when an <A> inside a <NAV> inside #header is clicked.
e.preventDefault(); // prevents the default click action
});
@andykillen
andykillen / always-have-a-default-first.js
Created June 18, 2016 14:16
Always have a default, and always check before trying to use that the selector responds with something
// you can do this
$('.class-to-find').each(function(index){
outputValue = $(this).text();
});
// but it will fail badly if there is nothing found by $('class-to-find').
//better to do
outputValue = ''; // set a default value
if($('.class-to-find').length){ // make sure that there is something to loop
$('.class-to-find').each(function(index){ // do the loop
var gulp = require('gulp');
var concat = require('gulp-concat');
// var minifyCSS = require('gulp-minify-css');
var minify = require("gulp-minify");
var cleanCSS = require('gulp-clean-css');
var rename = require("gulp-rename");
var autoprefixer = require('gulp-autoprefixer');
var sass = require('gulp-sass');
gulp.task('styles', function() {
@andykillen
andykillen / create-wget-for-bash.php
Last active December 15, 2016 16:44
Checks through a db looking for posts table and creates a text file with all the wget commands to retrieve the images of the site. To run just load the php file, enter the form fields and then after it has created the txt file run is 'bash wp_posts.txt' at the terminal.
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Search for all images on WordPress and download to directory via WGET task list</title>
</head>
<body>
<h1>Search for all images on WordPress and download to directory via WGET task list</h1>
<?php
@andykillen
andykillen / resize-images-to-1920px-wide.sh
Created December 16, 2016 19:33
Run this script in the wp-content/uploads directory, first making sure you have installed jpegoptim and pngcrush. change 1920> to 3.840> if you worry about @2x retina images
#!/bin/bash
for f in $(find . -name '*.jpg' -or -name '*.JPG' -or -name '*.JPEG' -or -name '*.jpeg' -or -name '*.png'); do
convert "$f" -resize "1920>" "$f";
@andykillen
andykillen / .gitignore
Created February 9, 2017 15:56
my standard gitignore for WP
/* ignore netbeans */
/nbproject/private/
/nbproject/
/* ignore WP core and misc for wordpress on */
wp-content/blogs.dir/
wp-content/upgrade/
wp-content/backup-db/
wp-content/advanced-cache.php
wp-content/wp-cache-config.php
@andykillen
andykillen / page-quizredirect.php
Created January 28, 2018 18:59
WordPress page template, redirect to Quiz url if not facebook.
<?php
/**
* Template Name: Facebook quiz redirect
*
**/
function check_if_facebook(){
/**
* this function checks if the current thing accessing the site is a facebook
* bot or not.