I just came across a great question in the WordPress.org Forums. It went something like this.

How do I change the default maximum number of featured posts displayed in the WordPress Twenty Fourteen Theme.

Accomplishing this task is not immediately obvious, but it’s not complicated. Here’s how.

What Is Featured Content In Twenty Fourteen?
The Twenty Fourteen theme gives users the ability to show off a number of posts on the Home page. Users can choose to display featured posts either in a grid layout or in a slider.

By going to Appearance > Customize, and locating the Featured Content section in the Customizer panel, it’s possible to select either Grid or Slider as the presentation options for the featured content.

Featured Content With Grid Option Of Customizer Panel In Twenty Fourteen Theme
Featured Content With Grid Option Of Customizer Panel In Twenty Fourteen Theme
Featured Content With Slider Option Of Customizer Panel In Twenty Fourteen Theme
Featured Content With Slider Option Of Customizer Panel In Twenty Fourteen Theme
In addition, you can enter a tag so that Twenty Fourteen singles out posts using that particular tag as being featured posts, or you can leave the relevant textbox blank. In the latter case, Twenty Fourteen will pick out Sticky Posts as the featured content to display on the main page.

To see these settings being applied, users only need to assign the appropriate tag to the posts they want to display as featured when the post is being created or edited, or designate them as sticky from the Publish box to the right of the post editor.

Publish Box In WordPress Post Editor
Publish Box In WordPress Post Editor
In this post, I’m only concerned with the Grid display option of the Featured Content.

By default, the maximum number of posts Twenty Fourteen displays is six. In the image below, my page only shows four posts, because this is all I have in my local WP install. If I had more, let’s say, ten featured posts, the page would show six featured posts in the grid.

Default Maximum Number Of Featured Posts Displayed In Twenty Fourteen Theme
Default Maximum Number Of Featured Posts Displayed In Twenty Fourteen Theme
However, let’s say we’d like to display only three featured posts. One easy way to do this, would be to assign the appropriate tag only to three posts.

This is all well and good, but we don’t want to rely on manual adjustments. We’d love to have our theme do this automatically. If you’re interested, here’s what you need to do to accomplish this task.

1: Create A Twenty Fourteen Child Theme

You’re going to modify a piece of functionality in the Twenty Fourteen theme, therefore a child theme is mandatory.

If you need some guidance on how to do this, please refer to this Codex article on how to create one.

2: Create A functions.php File

Inside your child theme, create a new functions.php file where you can add pieces of functionality to your child theme.

3: Modify Theme Support Settings For Featured Content

Open functions.php of your child theme inside a code editor, and add this chunk of code.

<?php

// Add support for featured content.
function twentyfourteen_child_setup () {
// This will remove support for featured content in the parent theme
remove_theme_support( ‘featured-content’ );

//This adds support for featured content in child theme
//with a different max_posts value of 3 instead of default 6
add_theme_support( ‘featured-content’, array(
‘featured_content_filter’ => ‘twentyfourteen_get_featured_posts’,
‘max_posts’ => 3,
) );
}

//Action hook for theme support
add_action( ‘after_setup_theme’, ‘twentyfourteen_child_setup’, 11);
The Twenty Fourteen theme leaves users the ability to modify the default maximum number of posts shown on the main page by changing the value of the second parameter of the add_theme_support function.

The code snippet above, deactivates the parent theme’s support settings for featured content and then reactivates theme support for featured content with a modified number of maximum posts. Now your child theme shouldn’t display more than three featured posts in the grid, no matter how many posts have been tagged with the appropriate tag or have been designated as Sticky.

Lower Default Maximum Number Of Featured Posts In Twenty Fourteen Theme
Lower Default Maximum Number Of Featured Posts In Twenty Fourteen Theme
My Theme Still Shows Six Featured Posts … What Can I Do?
It’s possible that you don’t see any changes in your child theme after you’ve performed the steps outlined above.

If this is the case, try one of the work-arounds below, one after the other, starting from the first one.

Toggle Between Slider And Grid In The Customizer
Head over to Appearance > Customize, locate the Featured Content section and perform the following steps.

Change the setting from Grid to Slider and save. Refresh the page in the browser
Reset the setting from Slider back to Grid and click Save & Publish in the Customizer. Refresh the page in the browser.
Get Your Hands On The Parent Theme (But Only Temporarily)
If by doing the above the new maximum number of featured posts doesn’t stick, try the following.

Open functions.php in the parent theme, but keep your child theme as the active theme.
Find the function twentyfourteen_setup() function in functions.php of the parent theme. Inside this function, locate the code that adds theme support for featured content (around line 108 of your code editor).
add_theme_support( ‘featured-content’, array(
‘featured_content_filter’ => ‘twentyfourteen_get_featured_posts’,
‘max_posts’ => 6,
) );
Change the max_posts value from 6 to 3. Save and refresh your page in the browser to check that your child theme is now displaying no more than three featured posts.

If you now see that no more than three featured posts are being displayed, go back to functions.php in the parent theme and reset max_posts back to its original value, six. Save the document.
Refresh your browser, and make sure your child theme still displays three featured posts. If it does, your modifications have stuck and your task has been successfully completed. Congratulations!
To Sum Up
In this post I’ve shown how to modify a piece of functionality in the WordPress Twenty Fourteen theme using functions.php.

In particular, I’ve shown how to change the default value of six to the maximum number of featured posts displayed in the blog listing’s page.

The specific instance considered here was about lowering the maximum number of featured posts from six to three. However, you can apply the same technique to increase that number. After all, displaying a full-page grid of posts would result in an interesting and contemporary layout.

How did this technique work for you? I’d love to hear all about it in the comments below.
About these ads

Leave a comment

Your email address will not be published.