__( 'Primary Menu', 'expound' ),
) );
/**
* Enable support for Post Formats
*/
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
/**
* Enable support for Custom Background
*/
add_theme_support( 'custom-background', array(
'default-color' => '333333',
) );
}
endif; // expound_setup
add_action( 'after_setup_theme', 'expound_setup' );
/**
* Register widgetized area and update sidebar with default widgets
*/
function expound_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'expound' ),
'id' => 'sidebar-1',
'before_widget' => '',
'before_title' => '
',
) );
}
add_action( 'widgets_init', 'expound_widgets_init' );
/**
* Enqueue scripts and styles
*/
function expound_scripts() {
wp_enqueue_style( 'expound-style', get_stylesheet_uri() );
wp_enqueue_script( 'expound-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script( 'expound-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'expound-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20120202' );
}
}
add_action( 'wp_enqueue_scripts', 'expound_scripts' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Additional helper post classes
*/
function expound_post_class( $classes ) {
if ( has_post_thumbnail() )
$classes[] = 'has-post-thumbnail';
return $classes;
}
add_filter('post_class', 'expound_post_class' );
/**
* Ignore and exclude featured posts on the home page.
*/
function expound_pre_get_posts( $query ) {
if ( ! $query->is_main_query() || is_admin() )
return;
if ( $query->is_home() ) { // condition should be (almost) the same as in index.php
$query->set( 'ignore_sticky_posts', true );
$exclude_ids = array();
$featured_posts = expound_get_featured_posts();
if ( $featured_posts->have_posts() )
foreach ( $featured_posts->posts as $post )
$exclude_ids[] = $post->ID;
$query->set( 'post__not_in', $exclude_ids );
}
}
add_action( 'pre_get_posts', 'expound_pre_get_posts' );
/**
* Returns a new WP_Query with featured posts.
*/
function expound_get_featured_posts() {
global $wp_query;
// Jetpack Featured Content support
$sticky = apply_filters( 'expound_get_featured_posts', array() );
if ( ! empty( $sticky ) )
$sticky = wp_list_pluck( $sticky, 'ID' );
if ( empty( $sticky ) )
$sticky = (array) get_option( 'sticky_posts', array() );
if ( empty( $sticky ) ) {
return new WP_Query( array(
'posts_per_page' => 5,
'ignore_sticky_posts' => true,
) );
}
$args = array(
'posts_per_page' => 5,
'post__in' => $sticky,
'ignore_sticky_posts' => true,
);
return new WP_Query( $args );
}
/**
* Returns a new WP_Query with related posts.
*/
function expound_get_related_posts() {
if ( method_exists( 'Jetpack_RelatedPosts', 'init_raw' ) ) {
$post_id = get_the_ID();
$related = Jetpack_RelatedPosts::init_raw()->set_query_name( 'MLT-Theme-Expound' )->get_for_post_id(
$post_id,
array(
'size' => 3,
)
);
$related_post_ids = array();
if ( $related ) {
foreach ( $related as $result ) {
$related_post_ids[] = $result['id'];
}
}
return new WP_Query( array(
'ignore_sticky_posts' => true,
'post__in' => $related_post_ids,
'orderby' => 'post__in',
) );
}
$post = get_post();
$args = array(
'posts_per_page' => 3,
'ignore_sticky_posts' => true,
'post__not_in' => array( $post->ID ),
);
// Get posts from the same category.
$categories = get_the_category();
if ( ! empty( $categories ) ) {
$category = array_shift( $categories );
$args['tax_query'] = array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $category->term_id,
),
);
}
return new WP_Query( $args );
}
/**
* Decrease caption width for non-full-width images. Pixelus perfectus!
*/
function expound_shortcode_atts_caption( $attr ) {
global $content_width;
if ( ! empty( $attr['width'] ) && is_numeric( $attr['width'] ) && $attr['width'] < $content_width && $attr['width'] >= 5 ) {
$attr['width'] = (int)$attr['width'] - 4;
}
return $attr;
}
add_filter( 'shortcode_atts_caption', 'expound_shortcode_atts_caption' );