5

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?

  • 3
    I recall scratching my head over this once here. – birgire Sep 29 '14 at 13:58
  • It's for the featured content in the Jetpack plugin. jetpack.me/support/featured-content – Steven Jones Sep 29 '14 at 18:55
  • As I stated in my post, I know that Jetpack offers this functionality but I'm not sure where Twenty Fourteen is getting it. This seems more suitable as a comment. – Bram Vanroy Sep 30 '14 at 7:01
  • @birgire With your post in mind I did some digging, and I found that Twenty Fourteen uses a modified version of Jetpack's Featured Content, which can be found in TwentyFourteen/inc/featured-content.php (Hence the last snippet in my OP). I do wonder what 'plugins.php' !== $GLOBALS['pagenow'] does though. Any ideas? – Bram Vanroy Sep 30 '14 at 7:03
  • It means the featured-content.php file will not be included when your'e on the plugins setup page in the backend. But I'm not exactly sure why you need this extra check. On the front end $GLOBALS['pagenow'] is usually index.php according to /wp-includes/vars.php. You can always try to remove the pagenow check on your test site to see if it generates any errors. – birgire Sep 30 '14 at 21:35
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.