Skip to content

Instantly share code, notes, and snippets.

View forrestbe's full-sized avatar

Forrest Brownlie forrestbe

View GitHub Profile
@forrestbe
forrestbe / es6-classes.js
Created October 28, 2016 12:37
Example of ES6 classes
// ES5
var DJ = (function() {
function MyConstructor(name) {
this.name = name;
}
MyConstructor.prototype.speak = function speak() {
console.log(this.name + ' is spinning some tunes.');
}
@forrestbe
forrestbe / template-literals.js
Created October 28, 2016 12:26
With ES6 we don't have to do more nesting concatenation
// ES5
var first = 'Forrest';
var last = 'Brownlie';
console.log('My name is ' + first + ' ' + last + '.');
// My name is Forrest Brownlie
// ES6
const firstName = 'Forrest';
const lastName = 'Brownlie';
console.log(`My name is ${firstName} ${lastName}`);
@forrestbe
forrestbe / mywidget-basic.php
Created June 23, 2016 22:32 — forked from pommiegranit/mywidget-basic.php
Playing with WordPress widgets
<?php
/*
Plugin Name: My Widget
Plugin URI: http://mydomain.com
Description: My first widget
Author: Me
Version: 1.0
Author URI: http://mydomain.com
*/
function get_excerpt_by_id($post_id){
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
$excerpt_length = 35; //Sets excerpt length by word count
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '…');
@forrestbe
forrestbe / wp-get-excerpt.php
Created May 30, 2016 02:20
Wordpress get excerpt by ID
function get_excerpt_by_id($post_id, $length)
{
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
$excerpt_length = $length; //Sets excerpt length by word count
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);