Skip to content

Instantly share code, notes, and snippets.

@ninnypants
ninnypants / truncate_post
Created October 22, 2011 04:03 — forked from whyisjake/js_excerpt
Simple function to Change the length of an excerpt.
<?php
## Truncate Post
function custom_excerpt_length(){
global $excerpt_length;
return $excerpt_length;
}
function custom_excerpt_more(){
global $excerpt_more;
@ninnypants
ninnypants / location_map.php
Created October 27, 2011 02:32
Map Shortcode
<?php
add_shortcode('map', 'location_map');
function location_map($atts){
$urlp = parse_url($atts['address']);
$q = parse_str($urlp['query']);
if(!empty($q['q'])){
return '<a href="'.$atts['address'].'"><img src="http://maps.google.com/maps/api/staticmap?center='.$q['q'].'&zoom=14&size='.$atts['w'].'x'.$atts['h'].'&maptype=roadmap&markers='.$q['q'].'&sensor=false" class="map" /></a>';
}
}
@ninnypants
ninnypants / jQuery with a PHP array...
Created October 27, 2011 04:20 — forked from whyisjake/jQuery with a PHP array...
Looking for an easy way to load a php array into some jQuery... Any ideas on how to simplify this?
<script>
post_ids = <?php echo json_encode(array(185,4,171)); ?>;
$(document).ready(function(){
/* Put your jQuery here */
$('.post-'+post_ids[1]).hide();
$('.post-'+post_ids[2]).hide();
$('.click'+post_ids[0]).addClass('active');
@ninnypants
ninnypants / in_tax.php
Created October 27, 2011 17:18
Test if a post is in a specific taxonomy
<?php
/*
** $taxonomy = Taxonomies to retrieve terms from
** $tax = Term slug or id to test against
*/
function in_tax($taxonomy, $tax){
global $post;
$taxes = array();
if(is_int($tax)){
$terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
@ninnypants
ninnypants / add-rules.php
Created October 27, 2011 17:20
Add rewrite rules to theme.
<?php
## Rewrite rules
add_filter( 'page_rewrite_rules','gcc_insert_rewrite_rules' );
add_filter( 'query_vars','gcc_insert_query_vars' );
add_action( 'wp_loaded','gcc_flush_rules' );
// flush_rules() if our rules are not yet included
function gcc_flush_rules(){
$rules = get_option( 'rewrite_rules' );
@ninnypants
ninnypants / yii_client_query.php
Created November 1, 2011 07:54
Yii Client Query
<?php
Client::model()->findAll(array(
'non_disclosure=:non_disclosure',
'questionnaire=:questionnaire',
'mod=:mod',
'initial_deposit=:initial_deposit',
),
array(
':non_disclosure' => 0,
':questionnaire' => 0,
@ninnypants
ninnypants / export-perms.php
Created November 10, 2011 18:17
Permalink export for Dustin Nay - changed location of function call.
<?php
add_filter('template_include', 'export_perms');
function export_perms(){
$posts = get_posts(array(
'post_type' => array('post', 'page'),
'numberposts' => -1,
));
$perms = '';
foreach($posts as $post){
setup_postdata($post);
@ninnypants
ninnypants / sort-arr-by-col.php
Created November 11, 2011 19:53
Sort an array by column
<?php
function arr_sort_by_column($arr_data, $str_column, $bln_desc = false)
{
$arr_data = (array) $arr_data;
$str_column = (string) trim($str_column);
$bln_desc = (bool) $bln_desc;
$str_sort_type = ($bln_desc) ? SORT_DESC : SORT_ASC;
foreach ($arr_data as $key => $row)
{
@ninnypants
ninnypants / for.php
Created November 14, 2011 01:53 — forked from whyisjake/gist:1363050
for
<?php get_header(); ?>
<div class="row">
<?php
global $wp_query;
$postid = $wp_query->post->ID;
$big_video = get_post_custom_values('Big_Video');
@ninnypants
ninnypants / gist:1372411
Created November 17, 2011 05:10 — forked from whyisjake/gist:1372394
functions for make:projects
function js_add_review($content) {
global $post;
$original = $content;
$content = js_ratings_box();
$content .= $original;
return $content;
}
add_filter( 'the_content', 'js_add_review', 15 );