Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / list-child-pages-only.php
Created Jan 26, 2012
WordPress - list only direct children pages, not all levels of child pages
View list-child-pages-only.php
<?php
/* List only child pages of a page - not grandchildren
*/
?>
<ul class="clearfix">
<?php wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) ); ?>
<?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
</ul>
@ramseyp
ramseyp / sharing_caring.php
Created Jan 31, 2012
Social Media Sharing code for WordPress articles
View sharing_caring.php
<?php
/* Add a social media share box to your WordPress site.
If you want the email sharing, you'll need to install WP-Email: http://wordpress.org/extend/plugins/wp-email/
Insert <?php s25_sharing_caring(); ?> to your template where you want the box to appear. Must be used inside the Loop.
Facebook Like Button code can be built here: http://developers.facebook.com/docs/reference/plugins/like/
Tweet Button code: https://dev.twitter.com/docs/tweet-button
LinkedIn Share Button: http://developer.linkedin.com/plugins/share-plugin-generator
Google Plus 1: http://www.google.com/webmasters/+1/button/
@ramseyp
ramseyp / wp_user-profile-fields.php
Created Jan 31, 2012
Add Extra Fields to WordPress user profile
View wp_user-profile-fields.php
<?php
/* Add Extra Profile Meta fields to WordPress user profile
*/
//Extra Author Profile Meta
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Is this an active author?</h3>
@ramseyp
ramseyp / myscript.js
Created Feb 16, 2012
Sample jquery script for prepending an image to a link
View myscript.js
jQuery(document).ready(function($){
$('a.fancybox').prepend('<img class="play" src="http://yoursite.com/path/to/img.png" alt="Play Video!" />');
});
@ramseyp
ramseyp / user-directory-page.php
Created Feb 23, 2012
WordPress User Directory - untested
View user-directory-page.php
<?php
/*
Template Name: User Directory
Inspirations for the code: @clarklab - http://clarklab.com/posts/sort-wordpress-users-by-custom-meta-value-with-get_users/
@scribu - http://scribu.net/wordpress/advanced-metadata-queries.html
*/
remove_action('genesis_loop', 'genesis_do_loop');
@ramseyp
ramseyp / videoshortcodes.php
Created Apr 11, 2012
Video shortcodes for Youtube, Vimeo, Ustream
View videoshortcodes.php
<?php
/* Shortcodes for Vimeo, Youtube, and Ustream
*
* @author Pat Ramsey
* @link http://slash25.com/vimeo-and-youtube-iframe-shortcodes/
* @param string $src,
* @param optional string $width, $height
* @return string iframe with modified strings $show_src, $show_width, $show_height
*
@ramseyp
ramseyp / custom-menu-metabox-field.php
Created Apr 17, 2012
Allow choosing of a custom menu and saving that value as postmeta
View custom-menu-metabox-field.php
<?php
/**
* Show custom menus as select list
* For use with CMB for WP: https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-field-types
* @author Travis Northcutt
* @link https://gist.github.com/2284508
*
* @param array $field
* @param string $meta
@ramseyp
ramseyp / merge_wp_arrays.php
Created Apr 25, 2012
Merge two wp_queries using array_merge
View merge_wp_arrays.php
<?php
/**
* Merging two queries
*
*/
$query1 = new WP_Query(array(
'post_type' => 'page',
'post_parent' => 341,
'post_status' => 'publish',
@ramseyp
ramseyp / age-check-genesis-theme.php
Created May 16, 2012
Functions for a Genesis child theme's splash page asking the visitor to certify he/she is over 21.
View age-check-genesis-theme.php
<?php
/**
* Set & read cookie for age-check in a Genesis child theme. On first visit to the site (any page)
* visitors are redirected to the page /age-check/. The age check page uses a custom page template
* containing part of the code here. The first two functions "set_newuser_cookie()"
* and "cur_page_url()" should go in your functions file.
* The code below that is for your custom page template.
*
* @author Pat Ramsey
*
@ramseyp
ramseyp / exc_format_query.php
Created Jun 7, 2012
Exclude a post format from the main query in WordPRess
View exc_format_query.php
<?php
/**
* Add a taxonomy query to pre_get_posts to remove Quote post formats from the main query
*
* @author Pat Ramsey
* @link http://slash25.com
*
* @param array tax_query $args
* @return modified $query
*/