Skip to content

Instantly share code, notes, and snippets.

Avatar

John Dugan johndugan

View GitHub Profile
@johndugan
johndugan / functions.php
Created Jul 12, 2012
WordPress: functions.php boilerplate
View functions.php
// ---------------------------------------------------------
// ---------- WordPress functions.php boilerplate ----------
// ---------------------------------------------------------
<?php
// ----------------------------------------------------------------------------
// ---------- Translations can be filed in the /languages/ directory ----------
// ----------------------------------------------------------------------------
load_theme_textdomain( 'html5reset', TEMPLATEPATH . '/languages' );
@johndugan
johndugan / wp_functions_customTaxonomy.php
Created Jul 12, 2012
WordPress: create custom taxonomy
View wp_functions_customTaxonomy.php
// ----------------------------------------------
// ---------- Create custom taxonomies ----------
// ----------------------------------------------
<?php
function custom_taxonomies() {
register_taxonomy('collection', 'post', array(
'hierarchical' => true,
'label' => 'Collections',
'query_var' => true,
'rewrite' => true
@johndugan
johndugan / wp_functions_customUserFields.php
Created Jul 12, 2012
WordPress: admin custom user fields
View wp_functions_customUserFields.php
// ----------------------------------------------------------
// ---------- Add customer user fields in wp admin ----------
// ----------------------------------------------------------
<?php
function modify_contactmethods( $contactmethods ) {
// Remove unwanted fields //
unset($contactmethods['aim']);
unset($contactmethods['yim']);
unset($contactmethods['jabber']);
// Add new fields //
@johndugan
johndugan / wp_functions_excerptElipsis.php
Created Jul 12, 2012
WordPress: custom excerpt elipsis
View wp_functions_excerptElipsis.php
// -------------------------------------------------------------------
// ---------- Change default [...] string for post excerpts ----------
// -------------------------------------------------------------------
<?php
function new_excerpt_more($more) {
return '{...}';
}
add_filter('excerpt_more', 'new_excerpt_more');
?>
@johndugan
johndugan / wp_functions_loopShortcode.php
Created Jul 12, 2012
WordPress: loop shortcode for pages
View wp_functions_loopShortcode.php
// --------------------------------------------------
// ---------- Create custom loop shortcode ----------
// --------------------------------------------------
// usage: [loop cat="17" posts_per_page="6" ]
// --------------------------------------------------
<?php
add_shortcode('loop', 'shortcode_query');
function shortcode_query($atts, $content){
extract(shortcode_atts(array( // a few default values. more query params at http://codex.wordpress.org/Class_Reference/WP_Query
@johndugan
johndugan / wp_functions_removePTagCatDesc.php
Created Jul 12, 2012
WordPress: remove <p> on category description
View wp_functions_removePTagCatDesc.php
// ------------------------------------------------------------------------------
// ---------- Remove the paragraph wrapper on the category description ----------
// ------------------------------------------------------------------------------
<?php
remove_filter('term_description','wpautop');
?>
View gist:3837604
<?php
for($i=0; $i<10; $i++) {
include("file.php");
}
?>
View gist:3837644
<?php
$i=0;
while($i<10) {
include("test.php");
$i++;
}
?>
@johndugan
johndugan / gist:3837726
Created Oct 5, 2012
PHP: for loop with break
View gist:3837726
// If "i" is equal to 10, break out of the loop and ignore the echo statement below.
<?php
for($i=0; $i<=10; $i++) {
echo $i;
if($i==10) {
break;
}
echo ", ";
}
@johndugan
johndugan / gist:3837750
Created Oct 5, 2012
PHP: for loop with continue
View gist:3837750
// If "i" is equal to 5, skip the echo statement below and continue evaluating the condition.
<?php
for($i=0; $i<=10; $i++) {
echo $i;
if($i==10) {
continue;
}
echo ", ";
}