Skip to content

Instantly share code, notes, and snippets.

View stevenspads's full-sized avatar

Steven stevenspads

View GitHub Profile
//In your terminal, type:
$ npm install express-handlebars —-save
//--save adds Handlebars to the Express dependencies
//Then open app.js and make sure the first few lines read as follows:
...
var bodyParser = require('body-parser');
//1. INSTALL EXPRESS GENERATOR
//Needed to generate Express projects
$ sudo npm install -g express-generator
//2. CREATE THE EXPRESS FOLDER STRUCTURE
$ express [project-name]
// how to write content to a file
$content = 'File content ...';
Storage::put( 'myfile.txt', $content );
// how to read content from a file
$content = Storage::get( 'myfile.txt' );
// how to delete a file
Storage::delete( 'myfile.txt' );
@stevenspads
stevenspads / Merge multiple WP_QUERY objects into one
Created July 12, 2016 19:34
Merging WP_QUERY objects in WordPress
//Your original 2 WP_Query results:
$query1 = new WP_Query($args_for_query1);
$query2 = new WP_Query($args_for_query2);
//Create a new WP_Query object to hold the joining of the 2 originals:
$joined_query = new WP_Query();
$joined_query->posts = array_merge( $query1->posts, $query2->posts );
@stevenspads
stevenspads / WordPress WP_QUERY Meta Key Sorter
Created July 9, 2016 05:34
WordPress Sorting WP_QUERY results by multiple meta keys
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'product',
'posts_per_page' => POSTS_PER_PAGE,
'paged' => $paged,
'meta_query' => array(
'relation' => 'AND',
'price' => array(
@stevenspads
stevenspads / WordPress ordering WP_QUERY results by several meta keys
Created July 9, 2016 05:27
Ordering WP_QUERY results by several meta keys in WordPress
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'games',
'author' => $user_id,
'meta_query' => array(
'relation' => 'AND',
'game_date' => array(
'key' => 'game_date',
@stevenspads
stevenspads / Installing Intervention Image in Laravel 5
Created July 8, 2016 03:00
Installing Intervention Image in Laravel 5
Installing Intervention Image in Laravel 5
1. Find the composer.json in your root directory and add "intervention/image": "2.*" in the require section:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"intervention/image": "2.*"
},
@stevenspads
stevenspads / WordPress Archive page loop
Created July 7, 2016 16:05
WordPress basic Archive page loop
<?php
if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
</header>
@stevenspads
stevenspads / WordPress display post archives by Year and Month
Last active October 11, 2019 05:28
Get WordPress post archives by Year and then by each Month per year. Display the results with Bootstrap styling.
<?php
global $wpdb;
$limit = 0;
$year_prev = null;
$months = $wpdb->get_results("SELECT DISTINCT MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = 'publish' and post_date <= now( ) and post_type = 'post' GROUP BY month , year ORDER BY post_date DESC");
foreach($months as $month) :
$year_current = $month->year;
@stevenspads
stevenspads / WordPress Get Monthly Archives
Created July 7, 2016 15:43
List monthly archives using Bootstrap styling
<ul class='list-group'>
<?php
$args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'custom',
'before' => '<li class="list-group-item">',
'after' => '</li>',
'show_post_count' => false,
'echo' => 1,