Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Created May 16, 2012 23:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregrickaby/2714731 to your computer and use it in GitHub Desktop.
Save gregrickaby/2714731 to your computer and use it in GitHub Desktop.
Thesis Child Theme
<?php
/**
* Functions.php
*
* This file handles the child theme setup and intialization.
*
* @category FMG
* @package Functions
* @author Greg Rickaby
* @since 1.0.0
* @alter 2012.06.03
* @link http://diythemes.com/thesis/rtfm/thesis-skin-starter-template/
*
*/
// Iinitial sanity check
if ( ! defined( 'ABSPATH' ) )
die( 'Please do not directly access this file' );
// Start the engine
include_once( TEMPLATEPATH . '/functions.php' );
/**
* Registers and builds the child theme by extendiding the thesis_custom_loop.
* This class is required for Thesis 2.0
*
* @category FMG
* @package Functions
* @author Greg Rickaby
* @since 1.0.0
* @requires Thesis 1.8.4+
*
*/
class thesis_child_theme extends thesis_custom_loop {
/**
* Run the parent constructor so we can access the thesis custom loop api.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct();
add_action( 'init', array( $this, 'init' ) );
}
/**
* Actions and filters that will run on init.
*
* @since 1.0.0
*/
public function init() {
$this->actions();
$this->filters();
$this->switch_skin();
$this->child_register_sidebars();
$this->child_initialize_cmb_meta_boxes();
$this->child_register_scripts();
$this->child_reg_post_type();
}
/**
* Generate CSS after switching to child theme.
*
* @since 1.0.0
*/
private function switch_skin() {
if ( is_admin() && ! get_option( __CLASS__ . '_generate' )) {
thesis_generate_css();
update_option( __CLASS__ . '_generate', 1 );
wp_cache_flush();
}
else return null;
}
/**
* Add and remove filters here.
*
* @since 1.0.0
*/
public function actions() {
remove_action( 'thesis_hook_header', 'thesis_default_header' );
remove_action( 'thesis_hook_before_header', 'thesis_nav_menu' );
remove_action( 'thesis_hook_after_post', 'thesis_comments_link' );
remove_action( 'thesis_hook_footer', 'thesis_attribution' );
remove_action( 'wp_head', array( 'nggGallery', 'nextgen_version' ) );
add_theme_support( 'post-thumbnails' );
add_image_size ( 'featured', 451, 230, true );
add_action( 'wp_enqueue_scripts', array( &$this, 'child_manage_scripts' ) );
add_action( 'thesis_hook_header', array( &$this, 'child_header' ) );
add_action( 'thesis_hook_before_post', array( &$this, 'child_byline' ) );
add_action( 'thesis_hook_after_post', array ( &$this, 'child_social_media_icons' ) );
add_action( 'thesis_hook_after_post_box', array ( &$this, 'child_fb_comments' ) );
add_action( 'thesis_hook_footer', array ( &$this, 'child_footer' ) );
}
/**
* Add and remove filters here.
*
* @since 1.0.0
*/
public function filters() {
add_filter( 'thesis_show_sidebars', 'no_sidebars' );
add_filter( 'thesis_body_classes', array ( &$this, 'child_body_class' ) );
add_filter( 'cmb_meta_boxes', array ( &$this, 'child_metaboxes' ) );
}
/**
* Enable custom stylesheets and scripts.
*
* @since 1.0.0
*/
public function child_register_scripts() {
if( !is_admin() ) {
wp_enqueue_style( 'fmg', get_bloginfo( 'stylesheet_directory' ) . '/style.css', '', false, 'screen, projection' );
wp_enqueue_script( 'megamenu', get_bloginfo( 'stylesheet_directory' ) . '/lib/js/jkmegamenu.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'fmg-scripts', get_bloginfo( 'stylesheet_directory' ) . '/lib/js/fmg.js', array( 'megamenu' ), false, true );
}
}
/**
* Enable WordPress body classes.
*
* @since 1.0.0
*/
public function child_body_class( $classes ) {
$bodyclasses = get_body_class();
foreach ( $bodyclasses as $bodyclass ) {
$classes[] .= $bodyclass;
}
return $classes;
}
/**
* Build custom header.
*
* @since 1.0.0
*/
public function child_header() { ?>
<a href="<?php echo get_home_url(); ?>"><p id="logo"></p></a>
<?php require_once( 'lib/nav.php' ); ?>
<?php include( 'lib/social-icons.php' ); ?>
<?php }
/**
* Build custom bylines for single posts.
*
* @since 1.0.0
*/
public function child_byline() { ?>
<p class="headline_meta"><?php thesis_author(); ?> <span class="published" title="<?php echo get_the_time('Y-m-d'); ?>"><?php echo get_the_time(get_option('date_format')); ?></span></p>
<p class="post_tags"><?php the_tags('Tagged as: <span>', ', ', '</span>'); ?></p>
<?php }
/**
* Build Social Media Icons for single posts.
*
* @since 1.0.0
*/
public function child_social_media_icons() {
if ( is_single() ) { ?>
<div id="social-media-icons">
<div class="facebook-button">
<div class="fb-like" data-send="false" data-layout="button_count" data-width="80" data-show-faces="false"></div>
</div>
<div class="twitter-button">
<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink(); ?>" data-text="<?php the_title(); ?>" data-via="QuirinRohleder">Tweet</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
<div class="gplus-button">
<g:plusone size="medium" href="<?php the_permalink(); ?>"></g:plusone>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
</div>
</div><!-- end #social-media-icons -->
<?php } }
/**
* Build Facebook comments for single posts.
*
* @since 1.0.0
*/
public function child_fb_comments() {
if ( is_single() ) { ?>
<div class="fb_comments">
<fb:comments href="<?php the_permalink(); ?>" numposts="10" width="977" publish_feed="true"></fb:comments>
</div>
<?php }
}
/**
* Build custom footer.
*
* @since 1.0.0
*/
public function child_footer() { ?>
<div class="creds left">
<h4>All Material Copyright Friday Managment Group</h4>
</div>
<?php include( 'lib/social-icons.php' ); ?>
<a href="#header_area"><div id="back-top"></div></a>
<div id="fb-root"></div>
<?php }
/**
* Manage stylesheets and scripts.
*
* @since 1.0.0
*/
public function child_manage_scripts() {
wp_dequeue_script( 'ngg-slideshow' );
wp_deregister_script( 'jquery-cycle' );
wp_dequeue_script( 'collapseomatic-js' );
wp_dequeue_style( 'collapseomatic-css' );
if ( is_front_page() ) {
wp_enqueue_script( 'collapseomatic-js' );
wp_enqueue_style( 'collapseomatic-css' );
}
if ( 'athletes' == get_post_type() ) {
wp_enqueue_script( 'collapseomatic-js' );
wp_enqueue_style( 'collapseomatic-css' );
}
}
/**
* Initialize custom meta boxes.
*
* @since 1.0.0
*/
public function child_initialize_cmb_meta_boxes() {
if ( !class_exists( 'cmb_Meta_Box' ) ) {
require_once( 'lib/metabox/init.php' );
}
}
/**
* The loop for the blog index page.
*
* @since 1.0.0
*/
public function home() {
require_once( 'lib/home.php' );
}
/**
* This loop is the default for category, tag, tax, author, day, month, year, and search pages.
*
* @since 1.0.0
*/
public function archive() {
require_once( 'lib/archives.php' );
}
/**
* The loop for displaying an individual post.
*
* @since 1.0.0
*/
public function single() {
if ( 'athletes' == get_post_type() ) {
require_once( 'lib/athletes.php' );
}
else thesis_loop::single();
}
/**
* See the complete list of Thesis Custom Loops: http://diythemes.com/thesis/rtfm/custom-loop-api/
*/
/**
* Register new sidebars.
*
* @since 1.0.0
*/
public function child_register_sidebars() {
register_sidebar(
array(
'id' => 'home-video',
'name' => 'Homepage Video',
'description' => 'Using a Text widget, paste &lt;iframe&gt; code here. Videos should be 699x477.',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar(
array(
'id' => 'home-about',
'name' => 'Homepage About',
'description' => 'Using a Text widget, write about your company here.',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar(
array(
'id' => 'home-gallery',
'name' => 'Homepage Gallery',
'description' => 'Drag and drop the NextGEN Widget here. Show: 32 thumbnails at 114x86.',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar(
array(
'id' => 'home-tweets',
'name' => 'Homepage Twitter',
'description' => 'Drag and drop Really Simple Twitter Feed Widget here.',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar(
array(
'id' => 'home-fbtimeline',
'name' => 'Homepage FaceAthelete',
'description' => 'Drag and drop a text widget containing FaceAthelete code.',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
}
/**
* Register new post type
*
* @since 1.0.0
*/
public function child_reg_post_type() {
$labels = array(
'name' => _x( 'Athlete', 'post type general name' ),
'singular_name' => _x( 'Athlete', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Athlete' ),
'add_new_item' => __( 'Add New Athlete' ),
'edit_item' => __( 'Edit Athlete' ),
'new_item' => __( 'New Athlete' ),
'all_items' => __( 'All Athletes' ),
'view_item' => __( 'View Athlete' ),
'search_items' => __( 'Search Athletes' ),
'not_found' => __( 'No Athletes found' ),
'not_found_in_trash' => __( 'No Athletes found in Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Athlete'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title' )
);
register_post_type( 'athletes', $args );
}
/**
* Define athlete metabox constants.
*
* @author Jared Atchison
* @since 1.0.0
* @requires Custom Metabox and Fields for WordPress
* @link: https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
*
*/
public function child_metaboxes( array $meta_boxes ) {
$prefix = '_cmb_';
$meta_boxes[] = array(
'id' => 'athletes_metabox',
'title' => 'Athletes Details',
'pages' => array( 'athletes', ),
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
'fields' => array(
array(
'name' => 'Athlete Name',
'desc' => 'Amie Fuller',
'id' => $prefix . 'athlete_name',
'type' => 'text_medium',
),
array(
'name' => 'Athlete Sport',
'desc' => 'Snowboarding',
'id' => $prefix . 'athlete_category',
'type' => 'text_medium',
),
array(
'name' => 'Video',
'desc' => 'Switch to the HTML Tab. Paste &lt;iframe&gt; code here. Videos should be 699x477.',
'id' => $prefix . 'athlete_video',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 3, ),
),
array(
'name' => 'Athlete Biography',
'desc' => '',
'id' => $prefix . 'athlete_biography',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
),
array(
'name' => 'Gallery ID',
'desc' => 'The NexGen Gallery ID',
'id' => $prefix . 'athlete_gallery',
'type' => 'text_small',
),
array(
'name' => 'Post Tag',
'desc' => 'The Post Tag slug e.g., aimee-fuller',
'id' => $prefix . 'athlete_tags',
'type' => 'text_small',
),
array(
'name' => 'Twitter Username',
'desc' => 'aimee_fuller',
'id' => $prefix . 'athlete_twitter_username',
'type' => 'text_medium',
),
array(
'name' => 'Instagram Username',
'desc' => 'aimee_fuller',
'id' => $prefix . 'athlete_instagram_username',
'type' => 'text_medium',
),
array(
'name' => 'FaceAthelete URI',
'desc' => 'https://www.faceAthelete.com/pages/Aimee-Fuller/219330391441195',
'id' => $prefix . 'athlete_faceAthelete',
'type' => 'text_medium',
),
),
);
return $meta_boxes;
}
}
new thesis_child_theme;
/**
* Helper Function: Return custom field post meta data.
*
* @since 1.0.0
*/
function thesis_get_custom_field( $field ) {
global $id, $post;
if ( null === $id && null === $post )
return false;
$post_id = null === $id ? $post->ID : $id;
$custom_field = get_post_meta( $post_id, $field, true );
if ( $custom_field )
// Sanitize and return the value of the custom field.
return stripslashes( wp_kses_decode_entities( $custom_field ) );
// Return false if custom field is empty.
return false;
}
/**
* Helper Function: Echo data from a post/page custom field.
*
* @since 1.0.0
*/
function thesis_custom_field( $field ) {
echo thesis_get_custom_field( $field );
}
add_filter( 'stylesheet_uri', 'child_stylesheet_uri' );
/**
* Cache bust the style.css reference.
*
*/
function child_stylesheet_uri( $stylesheet_uri ) {
return add_query_arg( 'v', filemtime( get_stylesheet_directory() . '/style.css' ), $stylesheet_uri );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment