Skip to content

Instantly share code, notes, and snippets.

View pdewouters's full-sized avatar
🌄
Working from home

Paul de Wouters pdewouters

🌄
Working from home
View GitHub Profile
@pdewouters
pdewouters / insertrecords
Created November 23, 2011 17:04
insertrecords
<?php
/*
* File: insertPersonData.php
* By: TMIT
* Date: 20100601
*
* This script sets up an ARRAY for tPerson field names
* and an ARRAY for 3 tPerson ROWs of data
*
@pdewouters
pdewouters / gist:1397570
Created November 27, 2011 13:43
custom search form widget
<?php
/*
Custom field search widget
This code adds a widget that allows to search for milepost ranges
*/
// use widgets_init action hook to execute custom function
add_action( 'widgets_init', 'wpyr_milepostwidget_register_widgets' );
@pdewouters
pdewouters / gist:1399949
Created November 28, 2011 10:47
enqueue scripts in plugin the right way
// guess current plugin directory URL
$plugin_url = plugin_dir_url(__FILE__);
//enqueue script
wp_enqueue_script('wpc_script', $plugin_url . 'js/script.js');
@pdewouters
pdewouters / select_dropdown_walker.php
Created November 28, 2011 18:59
select dropdown for WordPress custom menus
class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{
var $to_depth = -1;
function start_lvl(&$output, $depth){
$output .= '</option>';
}
function end_lvl(&$output, $depth){
$indent = str_repeat("\t", $depth); // don't output children closing tag
}
@pdewouters
pdewouters / wrap_post_images
Created November 28, 2011 22:45
wrap all post content images with extra tags
// behold the magic of regular expressions
// goes with http://www.cssplay.co.uk/menu/css3-photo-curl.html
function chiro_filter_images($content){
return preg_replace('/<img (.*) \/>\s*/iU', '<b class="curl"><b><img \1 /></b></b>', $content);
}
add_filter('the_content', 'chiro_filter_images');
<?php
// Create array for posts, we will stick the attachment post_parent in here
$posts = array();
// Get all images attached to post that have "Include in Rotator" marked as "Yes"
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => '-1',
@pdewouters
pdewouters / gist:1443656
Created December 7, 2011 17:17
Display taxonomy terms in an unordered list
// courtesy http://wpsnipp.com/index.php/posts/display-taxonomy-terms-in-an-unordered-list/
$terms = get_the_term_list( $post->ID, 'TAXONOMY_NAME',',',',','');
$terms = explode(',',$terms);
echo '<ul>';
for($i = 0;$i<sizeof($terms);$i++){ ?>
<li><? echo $terms[$i]; ?></li>
<? }
echo '</ul>';
@pdewouters
pdewouters / term dropdown select
Created January 11, 2012 01:33
suggestion for hierchical dropdown
case 'taxonomy_select':
$names= wp_get_object_terms( $post->ID, $field['taxonomy'] );
$terms = get_terms( $field['taxonomy'], 'hide_empty=0' );
$selected = '';
foreach ( $terms as $term ) {
if (!is_wp_error( $names ) && !empty( $names ) && !strcmp( $term->slug, $names[0]->slug ) ) {
$selected = $term->slug;
} else {
}
@pdewouters
pdewouters / glossary_template
Created January 18, 2012 13:13
glossary template, lists posts alphabetiaclly and displays an alphabetical nav bar
<?php
/**
* The glossary archive template
*/
/**
* Remove the standard loop
*/
remove_action( 'genesis_loop', 'genesis_do_loop' );
@pdewouters
pdewouters / remove_post_info_meta_genesis_cpt
Created January 25, 2012 21:12
remove post info and post meta from specific post type single template in genesis
//courtesy http://www.binaryturf.com/genesis-tip-remove-post-info-specific-custom-post-type/
add_filter('genesis_post_info', 'aha_post_info');
add_filter('genesis_post_meta', 'aha_post_meta');
function aha_post_info($post_info)
{
global $post;
if(get_post_type($post->ID) == 'ai1ec_event' )
{
return false;