Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Killen andykillen

View GitHub Profile
View standard-loop-get-latest-posts.php
<?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
View Change the Args of WP_Query.php
<?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
);
View exclude using php
$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 Jun 18, 2016
Its gives better performance to use a javascript object than it does to use a jQuery selector.
View use-js-objects-for-performance.js
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 Jun 18, 2016
Always have a default, and always check before trying to use that the selector responds with something
View always-have-a-default-first.js
// 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
View gulp.js
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 Dec 15, 2016
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.
View create-wget-for-bash.php
<!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 Dec 16, 2016
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
View resize-images-to-1920px-wide.sh
#!/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 Feb 9, 2017
my standard gitignore for WP
View .gitignore
/* 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 Jan 28, 2018
WordPress page template, redirect to Quiz url if not facebook.
View page-quizredirect.php
<?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.
You can’t perform that action at this time.