Skip to content

Instantly share code, notes, and snippets.

@illucent
illucent / gist:9290309
Created March 1, 2014 14:14
multilingual facebook like button
<?php
function facebook_javascript() {
global $q_config;
$fb_lang = 'de_DE';
switch ( $q_config['language'] ) {
case 'en': $fb_lang = 'en_US'; break;
case 'fr': $fb_lang = 'fr_FR'; break;
case 'it': $fb_lang = 'it_IT'; break;
case 'es': $fb_lang = 'es_ES'; break;
}
@illucent
illucent / gist:9329392
Created March 3, 2014 16:58
regex php for comma
// loop through posts, populating $departments arrays
foreach($posts as $post) {
$deps = strip_tags( get_post_meta( $post->ID, '_cmb_department_text', TRUE ));
preg_match_all("/,\s*/", $deps, $matches );
$result = array_combine($matches[1], $matches[2]);
$departments[$result][] = $post;
}
@illucent
illucent / gist:9370141
Created March 5, 2014 16:03
mysql wordpress
http://www.benmarshall.me/wordpress-sql-queries/#image-paths
<?php
/*
* Loop through Categories and Display Posts within
*/
$post_type = 'features';
// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( array( 'post_type' => $post_type ) );
foreach( $taxonomies as $taxonomy ) :
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@illucent
illucent / gist:9411279
Created March 7, 2014 13:15
array merge
photos_query = new WP_Query( $photos );
$quotes_query = new WP_Query( $quotes );
$result = new WP_Query();
// start putting the contents in the new object
$result->posts = array_merge( $photos_query->posts, $quotes_query->posts );
// here you might wanna apply some sort of sorting on $result->posts
// we also need to set post count correctly so as to enable the looping
@illucent
illucent / gist:9411300
Created March 7, 2014 13:17
wp loop examples
<?php
$term = get_term_by( 'slug', get_query_var( 'tag' ), "post_tag" );
$tagslug = $term->slug;
$post_types = get_post_types('','names');
?>
<?php
//first query
$blogposts = get_posts(array(
'tag' => $tagslug, //first taxonomy
'post_type' => $post_types,
@illucent
illucent / gist:9413430
Created March 7, 2014 15:22
pagination
<?php
$posts_per_page = 3; // how many posts per term
$taxonomy = 'category'; // taxonomy
$post_type = 'post'; // post type
$include_terms = array( 1, 25, 58 ); // the terms A B C ids
$post_count = $i = 0;
$custom_terms = get_terms( $taxonomy, array( 'parent' => 0, 'include' => $include_terms ) );
if ( $custom_terms ) :
@illucent
illucent / gist:9430689
Created March 8, 2014 13:34
first and last wordpress menu item
function add_menu_parent_class( $items ) {
// GET PARENT ITEMS
$parents = array();
foreach ( $items as $item ) {
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
}
# Install linux update, followed by GCC and Make
sudo yum -y update
sudo yum install -y gcc make
# Install Nginx and PHP-FPM
sudo yum install -y nginx php-fpm
# Install PHP extensions
sudo yum install -y php-devel php-mysql php-pdo \
php-pear php-mbstring php-cli php-odbc \