Skip to content

Instantly share code, notes, and snippets.

@NeilJS
NeilJS / gist:2575101
Created May 2, 2012 08:33
Cross-browser CSS3 transitionend event for event listeners
// CROSS-BROWSER TRANSITION END EVENT LISTENERS
var transEndEventNames = {
'WebkitTransition' : 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd',
'msTransition' : 'MSTransitionEnd',
'transition' : 'transitionend'
},
transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ]; // bind event listener to transEndEventName eg: this.addEventListener(transEndEventName, callbackFunction, false);
//alert(transEndEventName);
@NeilJS
NeilJS / gist:2146288
Created March 21, 2012 11:17
PHP if statements
PHP if statements around html blocks
<?php if ( x==y ) : ?>
<div>
Your html
</div>
<?php else : ?>
<div>
Your alternative html
</div>
@NeilJS
NeilJS / gist:2138342
Created March 20, 2012 17:21
WP - display tags as UL list
//Usual method, not in a list:
<?php
while (have_posts()) : the_post();
the_tags('','','');
endwhile;
?>
//Use wp_list_categories for UL:
<?php
wp_list_categories( array('taxonomy' => 'post_tag', 'title_li' => '', 'orderby' => 'name', 'order' => 'ASC') );
@NeilJS
NeilJS / gist:2137806
Created March 20, 2012 16:18
WP - Get current page number for current (single) post inc. CPTs
/* GET CURRENT PAGE NUMBER FOR THIS SINGLE POST ie. it's index number */
// put in functions.php
// Note: edit "my-custom-post-type" or remove "AND post_type = 'my-custom-post-type'"
function current_post_num($display=true) {
global $post, $wpdb;
//$rows = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date ASC");
$SQL = $wpdb->get_col("SELECT ID FROM $wpdb->posts posts WHERE posts.post_status = 'publish' AND post_type = 'my-custom-post-type' ORDER BY post_date ASC");
$SQL = array_flip($SQL);
$postnum = $SQL[$post->ID];
$postnum++;
@NeilJS
NeilJS / gist:2137474
Created March 20, 2012 16:00
WP - Get total number of posts in Custom Type Posts
// Put in functions.php
/* GET TOTAL NUMBER OF POSTS FOR SPECIFIC CUSTOM POST TYPE */
function cpt_count($ptype,$display=true) {
global $wpdb;
$SQL = "SELECT count(*) FROM $wpdb->posts posts WHERE posts.post_status = 'publish' AND post_type = '".$ptype."' ";
$total_cpt_posts = $wpdb->get_var($SQL);
if($display) {
echo $total_cpt_posts;
}
@NeilJS
NeilJS / gist:2115105
Created March 19, 2012 14:52
WP - Ensure custom post types work with category and tag searches
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','cpt'); // replace cpt to your custom post type
$query->set('post_type',$post_type);
return $query;
@NeilJS
NeilJS / WP rolescaps
Created October 18, 2011 09:47
Add / remove role capabilities in WP
// ADD CAPABILITIES FOR EDITOR ROLE
function update_capabilities() {
$role = get_role( 'editor' );
$caps_to_add = array(
'manage_options'
);
foreach( $caps_to_add as $cap )
$role->add_cap( $cap );
}
function remove_menu_pages() {
@NeilJS
NeilJS / functions.php
Created September 29, 2011 10:13
Replace Wordpress Howdy in admin top right
/**
* replace WordPress Howdy
*/
function goodbye_howdy($links)
{
$links = str_replace( 'Howdy', 'Hello', $links );
return $links;
}
add_filter( 'admin_user_info_links', 'goodbye_howdy' );