Skip to content

Instantly share code, notes, and snippets.

@ramseyp
ramseyp / list-child-pages-only.php
Created January 26, 2012 19:02
WordPress - list only direct children pages, not all levels of child pages
<?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 January 31, 2012 19:08
Social Media Sharing code for WordPress articles
<?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 January 31, 2012 19:45
Add Extra Fields to WordPress user profile
<?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 February 16, 2012 18:56
Sample jquery script for prepending an image to a link
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 February 23, 2012 17:09
WordPress User Directory - untested
<?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 April 11, 2012 15:40
Video shortcodes for Youtube, Vimeo, Ustream
<?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 April 17, 2012 03:54
Allow choosing of a custom menu and saving that value as postmeta
<?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 April 25, 2012 05:10
Merge two wp_queries using array_merge
<?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 20:13
Functions for a Genesis child theme's splash page asking the visitor to certify he/she is over 21.
<?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 June 7, 2012 05:27
Exclude a post format from the main query in WordPRess
<?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
*/