Skip to content

Instantly share code, notes, and snippets.

@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
@chasereeves
chasereeves / gist:898243
Created April 1, 2011 14:39
Remove Thesis Comment Count
//=========================================================== REMOVE THESIS COMMENT COUNT
remove_action('thesis_hook_after_post', 'thesis_comments_link');
@chasereeves
chasereeves / gist:899698
Created April 2, 2011 17:47
Latest Posts Loop
//=========================================================== Latest Posts Loop
function widget_latest_posts() {
$widget_latest_posts = new WP_Query('posts_per_page=3');
while ($widget_latest_posts->have_posts()) : $widget_latest_posts->the_post(); ?>
<div>
<h4><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title()?></a></h4>
<?php the_excerpt() ?>
<p class="widget_latest_posts_meta">Posted on <a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_date() ?></a></p>
</div>
@chasereeves
chasereeves / gist:906230
Created April 6, 2011 18:33
Add Google Analytics Async Code
//=========================================================== CUSTOM GOOGLE ANALYTICS
function custom_goog() { ?>
<!-- mathiasbynens.be/notes/async-analytics-snippet Change UA-XXXXX-X to be your site's ID -->
<script>
var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<?php } add_action('thesis_hook_before_html', 'custom_goog');
@chasereeves
chasereeves / gist:948919
Created April 29, 2011 19:54
Custom Excerpt length & words
//=========================================================== CUSTOM EXCERPT LENGTH & WORDS
function no_ellipsis($text) {
global $post;
return str_replace('[...]', '&hellip; <span class="read_more"><a href="' . get_permalink($post->ID) . '">Read More &raquo;</a></span>', $text);
}
add_filter('the_excerpt', 'no_ellipsis');
function new_excerpt_length($length) { return 20; }
add_filter('excerpt_length', 'new_excerpt_length');
@chasereeves
chasereeves / function is_has_child();
Created January 31, 2012 00:57
Wordpress test for whether current page is parent or child
function is_has_child() {
global $post;
if ( is_page() && $post->post_parent )
return true;
$children = get_pages('child_of='.$post->ID);
if( count( $children ) != 0 )
return true;
else
return false;
}
@chasereeves
chasereeves / gist:1713449
Created January 31, 2012 22:27
Add page classes to body tag: wp_page wp_post singular is_has_child single_author
//=========================================================== ADD PAGE BODY CLASS TO PAGES
function custom_page_bodyclass($classes) {
// add 'no-js' to body. Javascript in custom/js/script.js removes this when JS is active
$classes[] = 'no-js';
if ( is_page() ) { $classes[] = 'wp_page'; }
if ( is_single() ) { $classes[] = 'wp_post'; }
// is_singular is true for is_single(), is_page() or is_attachment()
if ( is_singular() ) { $classes[] = 'singular'; }
// is_has_child is true for a parent or a child page
if ( function_exists( 'is_has_child' ) && is_has_child() ) { $classes[] = 'is_has_child'; }
@chasereeves
chasereeves / gist:1713813
Created January 31, 2012 23:33
Create page sub navigation only for pages that contain and/or are children in Thesis theme.
<?php
/*
* Create page sub navigation only for pages that contain and/or are children in Thesis theme.
* ===========================================================================================
*/
// STEP 1: Create test for whether a page is and/or has children
function is_has_child() {
global $post;
if ( is_page() && $post->post_parent ) return true; // return "true" if current page has a parent
@chasereeves
chasereeves / Thesis Loop
Created February 19, 2012 02:57
Thesis Default Page Loop Elements
function page() {
global $post, $thesis_design;
while (have_posts()) { #wp
the_post(); #wp
$post_image = thesis_post_image_info('image');
thesis_hook_before_post_box();
echo "\t\t\t<div class=\"post_box top\" id=\"post-" . get_the_ID() . "\">\n"; #wp
thesis_hook_post_box_top();
thesis_headline_area(false, $post_image);
@chasereeves
chasereeves / gist:1974727
Created March 4, 2012 20:48
WP List children of a specific, known page. (e.g., Resources)
//=========================================================== SIDEBAR == Resources
function sidebar_resources() { ?>
<li class="widget widget_resources">
<h3>Resources</h3>
<ul>
<?php wp_list_pages('title_li=&child_of=614&sort_column=post_modified') ?>
</ul>
</li>
<?php }