Skip to content

Commit 0fe9b74

Browse files
committed
Twenty Fourteen: first pass at implementing Featured Content settings, props obenland. See #25549.
git-svn-id: https://develop.svn.wordpress.org/trunk@25808 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 96aa66a commit 0fe9b74

2 files changed

Lines changed: 472 additions & 12 deletions

File tree

src/wp-content/themes/twentyfourteen/functions.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ function twentyfourteen_setup() {
101101
'default-color' => 'f5f5f5',
102102
) ) );
103103

104+
/*
105+
* Add support for featured content.
106+
*/
107+
add_theme_support( 'featured-content', array(
108+
'featured_content_filter' => 'twentyfourteen_get_featured_posts',
109+
'max_posts' => 6,
110+
) );
111+
104112
/*
105113
* This theme uses its own gallery styles.
106114
*/
@@ -126,25 +134,22 @@ function twentyfourteen_content_width() {
126134
* Getter function for Featured Content Plugin.
127135
*
128136
* @since Twenty Fourteen 1.0
137+
*
138+
* @return array An array of WP_Post objects.
129139
*/
130140
function twentyfourteen_get_featured_posts() {
131-
return apply_filters( 'twentyfourteen_get_featured_posts', false );
141+
return apply_filters( 'twentyfourteen_get_featured_posts', array() );
132142
}
133143

134144
/**
135-
* A helper conditional function that returns a boolean value
136-
* So that we can use a condition like
137-
* if ( twentyfourteen_has_featured_posts( 1 ) )
145+
* A helper conditional function that returns a boolean value.
138146
*
139147
* @since Twenty Fourteen 1.0
148+
*
149+
* @return bool Whether there are featured posts.
140150
*/
141-
function twentyfourteen_has_featured_posts( $minimum = 1 ) {
142-
if ( is_paged() )
143-
return false;
144-
145-
$featured_posts = apply_filters( 'twentyfourteen_get_featured_posts', array() );
146-
147-
return is_array( $featured_posts ) && count( $featured_posts ) > absint( $minimum );
151+
function twentyfourteen_has_featured_posts() {
152+
return ! is_paged() && (bool) apply_filters( 'twentyfourteen_get_featured_posts', false );
148153
}
149154

150155
/**
@@ -352,7 +357,7 @@ function twentyfourteen_list_authors() {
352357
endif;
353358

354359
/**
355-
* Get recent formatted posts that are not featured in FC plugin.
360+
* Get recent formatted posts that are not featured in Featured Content area.
356361
*
357362
* @since Twenty Fourteen 1.0
358363
*
@@ -521,3 +526,12 @@ function twentyfourteen_wp_title( $title, $sep ) {
521526

522527
// Add Theme Customizer functionality.
523528
require get_template_directory() . '/inc/customizer.php';
529+
530+
/*
531+
* Add Featured Content functionality.
532+
*
533+
* To overwrite in a plugin, define your own Featured_Content class on or
534+
* before the 'setup_theme' hook.
535+
*/
536+
if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] )
537+
require get_template_directory() . '/inc/featured-content.php';

0 commit comments

Comments
 (0)