Skip to content

Instantly share code, notes, and snippets.

@vienhoang
vienhoang / gist:77e2bc5df65cbc3bcc8b
Created August 7, 2014 08:19
SCSS: Quick guide
SASS variables can come in six different types:
numbers | $myVar: 25px;
strings | $myStr: "some text string";
colors | $myColor: blue;
booleans | $myBool: false;
nulls | $myVar: null;
lists | $myList: 1px solid black; / $myMargin: 10px 10px 20px 10px;
/***********************************************************************************************/
@vienhoang
vienhoang / gist:242bb9e3cf0ea33e595e
Created August 9, 2014 13:43
PHP: Add url to text
function add_url_to_text( $text ) {
// Look for anything that is not a space, i = case insensitive, m = multiple line
$text = preg_replace('/(http[^s])+/im', '<a href="$1">$1</a>', $text );
return $text;
}
@vienhoang
vienhoang / messenger.php
Created August 11, 2014 16:21
WordPress: Custom widget
<?php
/*
Plugin Name: Messenger Widget
Plugin URI: http://vienhoang.com
Description: Display any messages.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / movies_post_type.php
Created August 11, 2014 16:22
WordPress: Custom post type
<?php
/*
Plugin Name: Movies Post Type
Plugin URI: http://vienhoang.com
Description: Offers a method for managing a movie collection.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / movies_post_type_shortcode.php
Created August 11, 2014 16:22
WordPress: Custom post type shortcode
<?php
add_shortcode( 'vh_movies', function() {
$loop = new WP_Query(
array(
'post_type' => 'vh_movie',
'orderby' => 'title'
)
);
if ( $loop->have_posts() ) {
@vienhoang
vienhoang / index.php
Created August 11, 2014 16:23
WordPress: Custom shortcode
<?php
/*
Plugin Name: Twitter Shower
Plugin URI: http://vienhoang.com
Description: Display message.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / vh_cron.php
Created August 11, 2014 16:23
WordPress: Custom cron job
<?php
/*
Plugin Name: VH Cron
Plugin URI: http://vienhoang.com
Description: Demo for running WP Cron Jobs
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / vh_filter.php
Created August 11, 2014 16:24
WordPress: Create custom filter
<?php
/*
Plugin Name: VH Filter
Plugin URI: http://vienhoang.com
Description: Filter the content.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / vh_options.php
Created August 11, 2014 16:24
WordPress: Create custom options page
<?php
/*
Plugin Name: VH Options
Plugin URI: http://vienhoang.com
Description: Options page for a theme.
Version: 1.0
Author: Vien Hoang
Author URI: http://vienhoang.com
License: GPL2
*/
@vienhoang
vienhoang / gist:e4c7dec93bd3e1c259ce
Created August 11, 2014 16:44
PHP: Break out of foreach func
function limiting($num) {
$fruits = array('bananas', 'apples', 'pear');
foreach ( $fruits as $v ) {
if ( $num-- === 0) {
break;
}