Skip to content

Instantly share code, notes, and snippets.

@chasereeves
chasereeves / gist:2296683
Created April 4, 2012 00:32
Wordpress list all posts by categories
<?php
foreach( get_categories('hide_empty=1','order_by=name') as $cat ) :
if( !$cat->parent ) {
echo '<h2><a href="#">' . $cat->name . '</a></h2>';
echo '<ul>';
process_cat_tree( $cat->term_id );
}
endforeach;
wp_reset_query(); //to reset all trouble done to the original query
@chasereeves
chasereeves / Wordpress Function: Social Meta Tags for Open Graph.php
Created November 24, 2015 17:18
Wordpress Function: Social Meta Tags for Open Graph
function insert_fb_in_head() {
global $post;
if ( !is_singular()) return;
$meta = strip_tags($post->post_content);
$meta = strip_shortcodes($post->post_content);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 125);
$meta = strip_tags($meta);
// basics, same for all
@chasereeves
chasereeves / gist:3885925
Created October 13, 2012 19:53
Wordpress Custom Meta Box
//=========================================================== Custom Meta Box - Video
$prefix = 'matterful_optionbox_';
$meta_box = array(
'id' => 'matterful_optionbox',
'title' => 'Ice Brimmin&rsquo; Options',
'page' => 'post',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
@chasereeves
chasereeves / gist:896638
Created March 31, 2011 15:57
Runx list of wordpress tags, reference, etc.
CONDITIONAL STATEMENTS
======================
is_home() .............................................When the user is on the blog home page
is_front_page() ............................................When the user is on the home page
is_single() ....................................................When the single post displayed
is_sticky() ........................................................Check if a post is sticky
is_page() ...........................................................When a page is displayed
is_category() ....................................................When a category is displayed
<?
//=========================================================== SUBSCRIBER SHORTCODE
function subscriber_shortcode($atts, $content = null ) {
extract(shortcode_atts(array(
'page' => '',
'headline' => 'Subscribe for free updates',
'button' => 'Subscribe',
'quote' => '',
'class' => 'box_main',
'form_class' => 'centered_form',
// [quotable]"Here's my quote."[/quotable]
// [quotable link="" class="" link_class=""]"Here's my quote."[/quotable]
// if link says 'no', use only content, no permalink
//=========================================================== TWEET THIS SHORTCODE
function quotable_shortcode( $atts, $content = null ) {
extract(shortcode_atts(array(
'class' => 'no_lede',
'link' => '',
'link_class' => '',
), $atts));
//=========================================================== PODLISTEN SHORTCODE
add_shortcode('podlisten', 'podlisten_shortcode');
// example: [podlisten src="http://your-site/videos/your-audio.mp3"]
function podlisten_shortcode($atts, $content = null) {
extract(shortcode_atts(array(
"src" => ''
), $atts));
return '
<div class="podlisten">
@chasereeves
chasereeves / gist:7093097
Created October 22, 2013 00:07
wordpress: Get first paragraph (first two if paragraph #1 isn't long enough).
//=========================================================== Grab first paragraph (two if first is not long enough)
function get_first_two_paragraphs(){
global $post;
$str = wpautop( get_the_content() );
$psToGrab = 2; // number of paragraphs to get
$maxFirstParaLength = 200; // character max in first paragraph
$matches = array(); // matching elements will go here
$pattern = '%<p[^>]*>(.*?)</p>%i'; // match what's between all <p> tags
preg_match_all($pattern, $str, $matches); // do the regex match
$outparts = array_slice($matches[1], 0, $psToGrab); // chop off everything after the first 2 elements
@chasereeves
chasereeves / gist:7093132
Created October 22, 2013 00:11
Wordpress shortcode for podcast file.
//=========================================================== PODLISTEN SHORTCODE
add_shortcode('podlisten', 'podlisten_shortcode');
// example: [podlisten src="http://your-site/videos/your-audio.mp3"]
function podlisten_shortcode($atts, $content = null) {
extract(shortcode_atts(array(
"src" => ''
), $atts));
return '
<hr class="big"/>
jQuery('a[href$="mp3"]').each(function(){
var audioURL = jQuery(this).attr('href');
var audioName = jQuery(this).text();
jQuery(this).before('<br/>');
jQuery(this).after('<br/><audio controls src="'+audioURL+'" type="audio/mpeg" preload="none"></audio><br/>');
});