Is “Featured Content” in Twenty Fourteen done with a plugin, or is it native in WP4.0?

I found that Twenty Fourteen offers users to have Featured Content on there websites. That’s great, because I had written my own little script for such an occasion. But if the functionality is already there in WP, I might as well use that.

However: When looking into Twenty Fourteen’s functions.php to investigate how it works, I see the following.

Adds the theme support.

// Add support for featured content. -- line 108-112
add_theme_support( 'featured-content', array(
    'featured_content_filter' => 'twentyfourteen_get_featured_posts',
    'max_posts' => 6,
) );

Not sure what the following does.

// line 132-159
/**
* Getter function for Featured Content Plugin.
 *
 * @since Twenty Fourteen 1.0
 *
 * @return array An array of WP_Post objects.
 */
function twentyfourteen_get_featured_posts() {
    /**
     * Filter the featured posts to return in Twenty Fourteen.
     *
     * @since Twenty Fourteen 1.0
     *
     * @param array|bool $posts Array of featured posts, otherwise false.
     */
    return apply_filters( 'twentyfourteen_get_featured_posts', array() );
}

/**
 * A helper conditional function that returns a boolean value.
 *
 * @since Twenty Fourteen 1.0
 *
 * @return bool Whether there are featured posts.
 */
function twentyfourteen_has_featured_posts() {
    return ! is_paged() && (bool) twentyfourteen_get_featured_posts();
}

Enqueue jQuery slider only if the featured content layout has been added into the modified theme.

// line 251-257
if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) {
    wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/slider.js', array( 'jquery' ), '20131205', true );
    wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', array(
        'prevText' => __( 'Previous', 'twentyfourteen' ),
        'nextText' => __( 'Next', 'twentyfourteen' )
    ) );
}

Adds core functionality of Featured Content. But how?

// line 507-516
/*
 * Add Featured Content functionality.
 *
 * To overwrite in a plugin, define your own Featured_Content class on or
 * before the 'setup_theme' hook.
 */
if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
    require get_template_directory() . '/inc/featured-content.php';
}

As might be clear from the questions above, I’m not sure how Featured Content works in this theme. I know that Jetpack allows Featured Content, but I can’t find any plugins that initiate this functionality in Twenty Fourteen. How then, does Twenty Fourteen do this? Has it included its own functionality of Featured Content, or did they borrow it from Jetpack?

1 Answer
1

The featured content is part of the TwentyFourteen theme, and is not implemented as a plugin, but rather as an Appearance > Customize setting (via get_theme_mod()), which allows the use of a Grid or Slider layout, choosing posts base on the tag provided.

BTW, I figured this out only after reading your post! So thanks for your question, it helped me a lot.

Leave a Comment