Posted by %3$s', 'reddle' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'reddle' ), get_the_author() ) ),
esc_html( get_the_author() )
);
}
endif;
if ( ! function_exists( 'reddle_the_attached_image' ) ) :
/**
* Prints the attached image with a link to the next attached image.
*/
function reddle_the_attached_image() {
$next_id = null;
$post = get_post();
$attachment_size = apply_filters( 'reddle_attachment_size', 1200 );
$attachment_size = array( $attachment_size, $attachment_size );
$next_attachment_url = wp_get_attachment_url();
if ( $post->post_parent ) {
/**
* Grab the IDs of all the image attachments in a gallery so we can get the
* URL of the next adjacent image in a gallery, or the first image (if
* we're looking at the last image in a gallery), or, in a gallery of one,
* just the link to that image file.
*/
$attachment_ids = get_posts( array(
'post_parent' => $post->post_parent,
'fields' => 'ids',
'numberposts' => 999,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
) );
// If there is more than 1 attachment in a gallery...
if ( is_countable( $attachment_ids ) && count( $attachment_ids ) > 1 ) {
foreach ( $attachment_ids as $idx => $attachment_id ) {
if ( $attachment_id == $post->ID ) {
$next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ];
break;
}
}
// get the URL of the next image attachment...
if ( $next_id )
$next_attachment_url = get_attachment_link( $next_id );
// or get the URL of the first image attachment.
else
$next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
}
}
printf( '%3$s',
esc_url( $next_attachment_url ),
the_title_attribute( array( 'echo' => false ) ),
wp_get_attachment_image( $post->ID, $attachment_size )
);
}
endif;
/**
* Adds custom classes to the array of body classes.
*
* @since Reddle 1.0
*/
function reddle_body_classes( $classes ) {
// We should always have content
$classes[] = 'primary';
// If we have 1 sidebar active we have secondary content
if ( is_active_sidebar( 'sidebar-1' ) || is_active_sidebar( 'sidebar-2' ) )
$classes[] = 'secondary';
// If we have both sidebars active we have tertiary content
if ( is_active_sidebar( 'sidebar-1' ) && is_active_sidebar( 'sidebar-2' ) )
$classes[] = 'tertiary';
/**
* What's going on here?
* If there is a 'secondary' class we can override our basic CSS structure to make a 2-column layout
* adding some page width and some CSS to accommodate one widget area
* and if there is a 'tertiary' class we can override our basic structure to make a 3-column layout
* adding more page width and some CSS to accommodate two widget areas
*/
// Adds a class of index to views that are not posts or pages or search
if ( ! is_singular() && ! is_search() ) {
$classes[] = 'indexed';
}
// Adds a class of single-author to blogs with only 1 published author
if ( ! is_multi_author() ) {
$classes[] = 'single-author';
}
// Add as a class of fixed or fluid depending on whether or not there is or isn't a header image
$header_image = get_header_image();
if ( empty( $header_image ) ) {
$classes[] = 'fluid';
} else {
$classes[] = 'fixed';
}
return $classes;
}
add_filter( 'body_class', 'reddle_body_classes' );
/**
* Adds custom classes to the array of post classes.
*
* @since Reddle 1.0
*/
function reddle_post_classes( $classes ) {
global $post;
// Adds a class of has-featured-image
if ( '' != get_the_post_thumbnail() ) {
$classes[] = 'has-featured-image';
}
return $classes;
}
add_filter( 'post_class', 'reddle_post_classes' );
/**
* Count the number of footer sidebars to enable dynamic classes for the footer
*
* @since Reddle 1.0
*/
function reddle_footer_sidebar_class() {
$count = 0;
if ( is_active_sidebar( 'sidebar-3' ) )
$count++;
if ( is_active_sidebar( 'sidebar-4' ) )
$count++;
if ( is_active_sidebar( 'sidebar-5' ) )
$count++;
$class = '';
switch ( $count ) {
case '1':
$class = 'one';
break;
case '2':
$class = 'two';
break;
case '3':
$class = 'three';
break;
}
if ( $class )
echo 'class="' . $class . '"';
}
/**
* Returns true if a blog has more than 1 category
*
* @since Reddle 1.0
*/
function reddle_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = is_countable( $all_the_cool_cats ) ? count( $all_the_cool_cats ) : 0;
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
// This blog has more than 1 category so reddle_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so reddle_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in reddle_categorized_blog
*
* @since Reddle 1.0
*/
function reddle_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'reddle_category_transient_flusher' );
add_action( 'save_post', 'reddle_category_transient_flusher' );
/**
* Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
*/
function reddle_enhanced_image_navigation( $url ) {
$post = get_post();
if ( wp_attachment_is_image() && ( $GLOBALS['wp_rewrite']->using_permalinks() && $post->post_parent > 0 && $post->post_parent != $post->ID ) )
$url = $url . '#main';
return $url;
}
add_filter( 'attachment_link', 'reddle_enhanced_image_navigation' );
/**
* Filters wp_title to print a neat tag based on what is being viewed.
*
* @since Reddle 1.0
*/
function reddle_wp_title( $title, $sep ) {
global $page, $paged;
if ( is_feed() )
return $title;
// Add the blog name
$title .= get_bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $sep $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $sep " . sprintf( __( 'Page %s', 'reddle' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'reddle_wp_title', 10, 2 );
/**
* Implement the Custom Header feature
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Load Jetpack compatibility file.
*/
if ( file_exists( get_template_directory() . '/inc/jetpack.php' ) )
require get_template_directory() . '/inc/jetpack.php';