Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / gist:1647598
Created January 20, 2012 14:31
Expanding taxonomy_select
case 'taxonomy_select':
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
$names= wp_get_object_terms( $post->ID, $field['taxonomy'] );
$terms = get_terms( $field['taxonomy'], 'hide_empty=0' );
if ( $field['options'] ) {
foreach ($field['options'] as $option) {
echo '<option value="', $option['value'], '"', $meta == $option['value'] ? ' selected="selected"' : '', '>', $option['name'], '</option>';
}
}
foreach ( $terms as $term ) {
@wpsmith
wpsmith / gist:1690040
Created January 27, 2012 17:59
CMB: Post Type Select
add_action( 'ntg_render_post_type_select' , 'wps_post_type_select' , 10 , 3 );
function wps_post_type_select ( $field, $meta, $id ) {
global $post;
if ( $field['type'] == 'post_type_select' ) {
echo '<select name="', $id, '" id="', $id, '">';
$pts = get_post_types();
if ( $field['options'] ) {
foreach ($field['options'] as $option) {
@wpsmith
wpsmith / gist:1690166
Created January 27, 2012 18:26
Taxonomy and Terms Dropdown
add_action( 'ntg_render_taxonomy_terms_select' , 'wps_taxonomy_terms_select' , 10 , 3 );
function wps_taxonomy_terms_select ( $field, $meta, $id ) {
global $post;
if ( $field['type'] == 'taxonomy_terms_select' ) {
echo '<select name="', $id, '" id="', $id, '" style="margin-top: 5px;">';
$pts = get_post_types();
echo '<option style="padding-right:10px;" value=""', selected ( $meta, '' ), '>', __( 'All Taxonomies and Terms', WPS_SLIDER ).'</option>';
if ( $field['options'] ) {
@wpsmith
wpsmith / gist:1690169
Created January 27, 2012 18:27
default case for admin-builder.php
default:
do_action( 'ntg_render_' . $field['type'] , $field, $meta , $this->get_field_name( $field['id'] ) );
@wpsmith
wpsmith / nothing.php
Created February 15, 2012 15:58
Trying to add "last-post" class to the loop
$post_classes = get_post_class();
$odd_or_even = 'even';
$post_counter = 0;
$post_counter++;
$odd_or_even = ( 'odd' == $odd_or_even ) ? 'even' : 'odd';
$post_classes[] = ( $post_counter == count( $posts ) ) ? 'last-post' :$odd_or_even;
echo '<div class="' . implode( ' ', $post_classes ) . '">';
@wpsmith
wpsmith / radio-latest-news-widget.php
Created February 15, 2012 18:47 — forked from gregrickaby/radio-latest-news-widget.php
If there's no content, don't display [Continue...]
if ( ! empty( $instance['show_content'] ) ) {
if ( 'excerpt' == $instance['show_content'] )
the_excerpt();
elseif ( 'content-limit' == $instance['show_content'] && strip_shortcodes( get_the_content() ) != '' )
the_content_limit( (int) $instance['content_limit'], esc_html( $instance['more_text'] ) );
else
the_content( esc_html( $instance['more_text'] ) );
}
@wpsmith
wpsmith / gist:1926880
Created February 27, 2012 20:39
get custom field
function genesis_get_custom_field($field, $single = true) {
global $id, $post;
if ( null === $id && null === $post ) {
return false;
}
$post_id = null === $id ? $post->ID : $id;
@wpsmith
wpsmith / genesis-favicon.php
Created March 3, 2012 04:26
Loads favicon from a specified URL
// Loads favicon from specified URL
add_filter( 'genesis_pre_load_favicon', 'wps_custom_favicon_filter' );
function wps_custom_favicon_filter( $favicon_url ) {
return 'http://domain.com/path/mycustomfavicon.ico';
}
@wpsmith
wpsmith / embed-objects.php
Created March 3, 2012 04:35
Changes the default embed sizes based on conditionals
add_filter( 'embed_defaults', 'wps_embed_defaults' );
/**
* Changes the default embed sizes based on site layout
* @author Travis Smith
*
* @param array height and width keys, values can be string/int
* @return array height and width keys and values
*/
function wps_embed_defaults( $defaults ) {
@wpsmith
wpsmith / genesis-embed-objects.php
Created March 3, 2012 04:37
Changes the default embed sizes based on site layout
add_filter( 'embed_defaults', 'wps_embed_defaults' );
/**
* Changes the default embed sizes based on site layout
* via filtering wp_embed_defaults()
*
* @author Travis Smith
*
* @param array height and width keys, values can be string/int
* @return array height and width keys and values
*/