is_main_query() || ! itheme2_featuring_posts() ) return $query; // Exclude featured posts from the main query $query->query_vars['post__not_in'] = itheme2_featuring_posts(); return $query; } add_action( 'pre_get_posts', 'itheme2_home_posts' ); /** * Test to see if any posts meet our conditions for featuring posts. * Current conditions are: * * - sticky posts * - with featured thumbnails * * We store the results of the loop in a transient, to prevent running this * extra query on every page load. The results are an array of post ID's that * match the result above. This gives us a quick way to loop through featured * posts again later without needing to query additional times later. */ function itheme2_featuring_posts( $force_update = false ) { $featured_post_ids = []; if ( $force_update || ( false === ( $featured_post_ids = get_transient( 'featured_post_ids' ) ) ) ) { // Proceed only if sticky posts exist. $sticky = get_option( 'sticky_posts' ); // Proceed only if sticky posts exist. if ( ! empty( $sticky ) && is_array( $sticky ) ) { $featured_args = array( 'post__in' => $sticky, 'post_status' => 'publish', 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'posts_per_page' => 30, ); // The Featured Posts query. $featured = new WP_Query( $featured_args ); // Proceed only if published posts with thumbnails exist if ( $featured->have_posts() ) { while ( $featured->have_posts() ) { $featured->the_post(); if ( '' != get_the_post_thumbnail( $featured->post->ID ) ) { $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 itheme2_featuring_posts() * * @since iTheme2 1.2 */ function itheme2_featured_post_checker_flusher() { // Vvwooshh! delete_transient( 'featured_post_ids' ); } add_action( 'update_option_sticky_posts', 'itheme2_featured_post_checker_flusher' ); add_action( 'save_post', 'itheme2_featured_post_checker_flusher' ); /** * Enqueue scripts and styles */ function itheme2_script_enqueue() { wp_enqueue_style( 'itheme2', get_stylesheet_uri() ); if ( itheme2_featuring_posts() ) wp_enqueue_script( 'jcarousel', get_template_directory_uri() . '/js/jcarousel.js', array( 'jquery' ), false, true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); } add_action( 'wp_enqueue_scripts', 'itheme2_script_enqueue' ); function itheme2_footer_scripts() { if ( itheme2_featuring_posts() ) { ?> __( 'Primary Menu', 'itheme2' ), ) ); /** * Add support for Post Formats */ add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery' ) ); /** * Add support for custom backgrounds */ add_theme_support( 'custom-background' ); /** * Add in support for post thumbnails */ add_theme_support( 'post-thumbnails' ); add_image_size( 'large-feature', 593, 261, true ); // Used for large feature images above the post add_image_size( 'small-feature', 145, 120, true ); // Used for small feature images in the carousel on the home page add_theme_support( 'print-style' ); } endif; // itheme2_setup function itheme2_custom_header_setup() { add_theme_support( 'custom-header', apply_filters( 'itheme2_custom_header_args', array( 'default-image' => '', 'default-text-color' => 'fff', 'random-default' => false, 'width' => 978, 'height' => 288, 'wp-head-callback' => 'itheme2_header_style', 'admin-head-callback' => 'itheme2_admin_header_style', 'admin-preview-callback' => 'itheme2_admin_header_image', ) ) ); } add_action( 'after_setup_theme', 'itheme2_custom_header_setup' ); if ( ! function_exists( 'itheme2_header_style' ) ) : /** * Styles the header image and text displayed on the blog */ function itheme2_header_style() { // If no custom options for text are set, let's bail // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value if ( HEADER_TEXTCOLOR == get_header_textcolor() ) return; // If we get this far, we have custom styles. Let's do this. ?> Header admin panel. * * @since iTheme2 1.0 */ function itheme2_admin_header_style() { ?> Header admin panel. * * @since iTheme2 1.0 */ function itheme2_admin_header_image() { ?>

onclick="return false;" href="">

>
' . __( 'Continue reading ', 'itheme2' ) . ''; } /** * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and itheme2_continue_reading_link(). * * To override this in a child theme, remove the filter and add your own * function tied to the excerpt_more filter hook. */ function itheme2_auto_excerpt_more( $more ) { return ' …' . itheme2_continue_reading_link(); } add_filter( 'excerpt_more', 'itheme2_auto_excerpt_more' ); /** * Adds a pretty "Continue Reading" link to custom post excerpts. * * To override this link in a child theme, remove the filter and add your own * function tied to the get_the_excerpt filter hook. */ function itheme2_custom_excerpt_more( $output ) { if ( has_excerpt() && ! is_attachment() ) { $output .= itheme2_continue_reading_link(); } return $output; } add_filter( 'get_the_excerpt', 'itheme2_custom_excerpt_more' ); /** * Set a default theme color array for WP.com. */ $themecolors = array( 'bg' => 'ffffff', 'border' => 'eeeeee', 'text' => '444444', ); /** * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. */ function itheme2_page_menu_args( $args ) { $args['show_home'] = true; return $args; } add_filter( 'wp_page_menu_args', 'itheme2_page_menu_args' ); /** * Register widgetized area and update sidebar with default widgets */ function itheme2_widgets_init() { register_sidebar( array( 'name' => __( 'Sidebar 1', 'itheme2' ), 'id' => 'sidebar-1', 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Sidebar 2', 'itheme2' ), 'id' => 'sidebar-2', 'description' => __( 'An optional second sidebar area', 'itheme2' ), 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'init', 'itheme2_widgets_init' ); if ( ! function_exists( 'itheme2_content_nav' ) ): /** * Display navigation to next/previous pages when applicable * * @since iTheme2 1.2 */ function itheme2_content_nav( $nav_id ) { global $wp_query; ?> comment_type ) : case 'pingback' : case 'trackback' : ?>
  • id="li-comment-">
    $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    Posted on by ', 'itheme2' ), 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', 'itheme2' ), get_the_author() ) ), esc_html( get_the_author() ) ); } endif; /** * Adds custom classes to the array of body classes. * * @since iTheme2 1.2 */ function itheme2_body_classes( $classes ) { // Adds a class of indexed to index and archive views if ( is_home() || is_archive() ) $classes[] = 'indexed'; // Adds a class of single-author to blogs with only 1 published author if ( ! is_multi_author() ) $classes[] = 'single-author'; return $classes; } add_filter( 'body_class', 'itheme2_body_classes' ); /** * Returns true if a blog has more than 1 category * * @since iTheme2 1.2 */ function itheme2_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 itheme2_categorized_blog should return true return true; } else { // This blog has only 1 category so itheme2_categorized_blog should return false return false; } } /** * Flush out the transients used in itheme2_categorized_blog * * @since iTheme2 1.2 */ function itheme2_category_transient_flusher() { // Like, beat it. Dig? delete_transient( 'all_the_cool_cats' ); } add_action( 'edit_category', 'itheme2_category_transient_flusher' ); add_action( 'save_post', 'itheme2_category_transient_flusher' ); /** * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages */ function itheme2_enhanced_image_navigation( $url ) { global $post, $wp_rewrite; if ( isset( $post->ID ) ) { $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', 'itheme2_enhanced_image_navigation' ); /** * WP.com: A dynamic $themecolors array for all of our alternate color schemes */ $options = get_option( 'itheme2_theme_options' ); $color_scheme = $options['color_scheme'] ?? null; switch ( $color_scheme ) { case 'gray': $themecolors = array( 'bg' => 'efefef', 'border' => 'cccccc', 'text' => '666666', 'link' => '026acb', 'url' => '026acb', ); break; case 'black': $themecolors = array( 'bg' => '222222', 'border' => '555555', 'text' => 'aaaaaa', 'link' => '026acb', 'url' => '026acb', ); break; default: $themecolors = array( 'bg' => 'ffffff', 'border' => 'dddddd', 'text' => '666666', 'link' => '026acb', 'url' => '026acb', ); break; } /** * Appends post title to Aside and Quote posts * * @param string $content * @return string */ function itheme2_conditional_title( $content ) { if ( has_post_format( 'aside' ) || has_post_format( 'quote' ) ) { if ( ! is_singular() ) $content .= the_title( '

    ', '

    ', false ); else $content .= the_title( '

    ', '

    ', false ); } return $content; } add_filter( 'the_content', 'itheme2_conditional_title', 0 ); /** * Filters wp_title to print a neat tag based on what is being viewed. * * @since iTheme2 1.1 */ function itheme2_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', 'itheme2' ), max( $paged, $page ) ); return $title; } add_filter( 'wp_title', 'itheme2_wp_title', 10, 2 ); /** * This theme was built with PHP, Semantic HTML, CSS, love, and a iTheme2. */