Posted on by %7$s', 'forever' ),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'forever' ), get_the_author() ) ),
esc_html( get_the_author() )
);
}
endif;
/**
* Adds custom classes to the array of body classes.
*
* @since Forever 1.0
*/
function forever_body_classes( $classes ) {
// Adds a class of single-author to blogs with only 1 published author
if ( ! is_multi_author() ) {
$classes[] = 'single-author';
}
// Adds a class of index to views that are not posts or pages or search
if ( ! is_singular() && ! is_search() ) {
$classes[] = 'indexed';
}
return $classes;
}
add_filter( 'body_class', 'forever_body_classes' );
/**
* Count the number of footer sidebars to enable dynamic classes for the footer
*/
function forever_footer_sidebar_class() {
$count = 0;
if ( is_active_sidebar( 'sidebar-2' ) )
$count++;
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;
case '4':
$class = 'four';
break;
}
if ( $class )
echo 'class="' . $class . '"';
}
/**
* Returns true if a blog has more than 1 category
*
* @since Forever 1.0
*/
function forever_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 forever_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so forever_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in forever_categorized_blog
*
* @since Forever 1.0
*/
function forever_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'forever_category_transient_flusher' );
add_action( 'save_post', 'forever_category_transient_flusher' );
/**
* Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
*/
function forever_enhanced_image_navigation( $url ) {
global $post, $wp_rewrite;
// Bail if there is no $post, like in the dashboard recent comments widget.
if ( ! isset( $post ) )
return $url;
$id = (int) $post->ID;
$object = get_post( $id );
if ( wp_attachment_is_image( $post->ID ) && ( $wp_rewrite->using_permalinks() && ( $object->post_parent > 0 ) && ( $object->post_parent != $id ) ) )
$url = $url . '#main';
return $url;
}
add_filter( 'attachment_link', 'forever_enhanced_image_navigation' );
/**
* Filter the home page posts, and remove any featured post IDs from it. Hooked
* onto the 'pre_get_posts' action, this changes the parameters of the query
* before it gets any posts.
*
* @global array $featured_post_id
* @param WP_Query $query
* @return WP_Query Possibly modified WP_query
*/
function forever_home_posts( $query = false ) {
// Bail if not home, not a query, not main query.
if ( ! is_home() || ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() )
return $query;
$featured = forever_featured_posts();
$recent = apply_filters( 'forever-recent-posts', false );
// Bail if no featured posts.
if ( ! $featured && ! $recent )
return $query;
// Exclude featured posts from the main query.
$query->query_vars['post__not_in'] = array_merge( (array) $featured, (array) $recent );
return $query;
}
add_action( 'pre_get_posts', 'forever_home_posts' );
/**
* Test to see if any posts meet our conditions for featuring posts.
*
* @return mixed Array of featured post ids on success, false on failure.
*/
function forever_featured_posts() {
$featured_post_ids = get_transient( 'featured_post_ids' );
// Return cached results.
if ( ! empty( $featured_post_ids ) )
return $featured_post_ids;
$sticky_posts = get_option( 'sticky_posts' );
// Proceed only if sticky posts exist.
if ( empty( $sticky_posts ) || ! is_array( $sticky_posts ) )
return false;
// The Featured Posts query.
$featured = new WP_Query( array(
'post__in' => $sticky_posts,
'post_status' => 'publish',
'no_found_rows' => true,
'ignore_sticky_posts' => 1,
'posts_per_page' => 50,
) );
// Proceed only if published posts exist.
if ( ! $featured->have_posts() )
return false;
$sizes = forever_get_image_sizes();
$min_width = 888;
if ( isset( $sizes['large-feature'][0] ) )
$min_width = $sizes['large-feature'][0];
while ( $featured->have_posts() ) {
$featured->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $featured->post->ID ), 'large-feature' );
if (
$image
&& isset( $image[1] )
&& $min_width <= $image[1]
) {
$featured_post_ids[] = $featured->post->ID;
}
}
set_transient( 'featured_post_ids', $featured_post_ids );
wp_reset_postdata();
return $featured_post_ids;
}
/**
* Flush out the transients used in forever_featured_posts()
*
* Hooks into the "save_post" and "update_option_sticky_posts" actions.
*
* Vvwooshh!
*/
function forever_featured_post_checker_flusher() {
delete_transient( 'featured_post_ids' );
}
add_action( 'update_option_sticky_posts', 'forever_featured_post_checker_flusher' );
add_action( 'save_post', 'forever_featured_post_checker_flusher' );
require_once __DIR__ . '/inc/custom-header.php' ;
/**
* Filters wp_title to print a neat tag based on what is being viewed.
*
* @since Forever 1.1
*/
function forever_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', 'forever' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'forever_wp_title', 10, 2 );
/*
* Remove widont filter if Posts in Columns options is active
*
* @since Forever 1.2.2
*/
function forever_wido() {
if ( ! function_exists( 'forever_get_theme_options' ) ) {
return false;
}
$options = forever_get_theme_options();
if ( 'on' != $options['posts_in_columns'] ) {
return false;
}
remove_filter( 'the_title', 'widont' );
}
add_action( 'init', 'forever_wido' );
/**
* Show a nice admin message saying Forever has an update in the form of Toujours.
*/
function forever_change_notice() {
$theme_link = admin_url( 'themes.php?s=toujours' );
?>