Skip to content

Instantly share code, notes, and snippets.

@billerickson
billerickson / functions.php
Last active January 21, 2021 01:17
Use the built-in post counter
<?php
/**
* Use the built-in post counter
*
* Sometimes you'll want to keep track of which post you're on in a loop.
* Some people create their own $loop_counter (ex: Genesis, https://gist.github.com/4675237 ).
* There's a better way! A loop counter is built into $wp_query. Ex:
*
* global $wp_query;
* echo $wp_query->current_post
<?php
/**
* Featured Image on Single Posts
*
*/
function be_single_featured_image() {
if( is_single() && has_post_thumbnail() )
echo '<p class="featured-image">' . get_the_post_thumbnail( null, 'large' ) . '</p>';
}
<?php
/**
* Grid Loop on Portfolio archive
*
* @author Bill Erickson
* @link https://github.com/billerickson/Genesis-Grid/wiki/Home
*
* @param bool $grid, whether to use grid loop
* @param object $query, the WP Query
* @return bool
<?php
// Our large image size
add_image_size( 'be_large', 500, 500, true );
/**
* Genesis Grid - Use different image on CPT archive
*
* @author Bill Erickson
* @link http://wordpress.org/support/topic/filter-the-image-for-cpt-archive
/**
* Limit homepage to one category
*
*/
function be_home_query( $query ) {
if( $query->is_main_query() && $query->is_home() && !is_admin() )
$query->set( 'category_name', 'sample-category' );
}
add_action( 'pre_get_posts', 'be_home_query' );
@ocean90
ocean90 / auto-embeds-disabler.php
Created September 27, 2012 21:42
WordPress Plugin: Auto-embeds Disabler
<?php
/**
* Plugin Name: Auto-embeds Disabler
* Version: 0.1
* Description: Disables the auto-embeds function in WordPress 3.5
* Author: Dominik Schilling
* Author URI: http://wphelper.de/
* Plugin URI: http://wpgrafie.de/1078/
*
*
@jaredatch
jaredatch / gist:3764381
Last active October 10, 2015 22:58
Customize image size used in the loop by Genesis
<?php
/**
* Customize image size used in the loop by Genesis
*
* @author Jared Atchison
* @link http://jaredatchison.com/code/
* @param string $image_size
* @global array $wp_query
* @global int $loop_counter
* @return string
@jaredatch
jaredatch / gist:3759896
Created September 21, 2012 05:37 — forked from billerickson/gist:3698476
WP: Query $args
<?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(
@billerickson
billerickson / gist:3714550
Created September 13, 2012 14:09 — forked from anonymous/gist:3712088
Sample Child Theme with Post Format
<?php
/** Start the engine */
require_once( get_template_directory() . '/lib/init.php' );
/** Child theme (do not remove) */
define( 'CHILD_THEME_NAME', 'Sample Child Theme' );
define( 'CHILD_THEME_URL', 'http://www.studiopress.com/themes/genesis' );
/** Add Viewport meta tag for mobile browsers */
add_action( 'genesis_meta', 'add_viewport_meta_tag' );
@unix7
unix7 / gist:3707162
Created September 12, 2012 14:53
Exclude Certain Post Format from Blog Loop
//Source: http://www.billerickson.net/customize-the-wordpress-query/#example-category
<?php
/**
* Exclude Post Formats from Blog
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*