Skip to content

Instantly share code, notes, and snippets.

@mikeyarce
Last active August 29, 2015 14:23
Show Gist options
  • Save mikeyarce/a0a662a2ccdc46784392 to your computer and use it in GitHub Desktop.
Save mikeyarce/a0a662a2ccdc46784392 to your computer and use it in GitHub Desktop.
Jetpack's Featured Content
// Add Theme support and write a function to get the featured posts
// This goes in your themes functions.php file
add_theme_support( 'featured-content', array(
'filter' => 'mytheme_get_featured_posts',
'max_posts' => 20,
'post_types' => array( 'post', 'page' ),
) );
function mytheme_get_featured_posts() {
return apply_filters( 'mytheme_get_featured_posts', array() );
}
function mytheme_has_featured_posts( $minimum = 1 ) {
if ( is_paged() )
return false;
$minimum = absint( $minimum );
$featured_posts = apply_filters( 'mytheme_get_featured_posts', array() );
if ( ! is_array( $featured_posts ) )
return false;
if ( $minimum > count( $featured_posts ) )
return false;
return true;
}
// Now lets call the featured posts using a template part
// In this scenario, you are only wanting them to show up on your front page
<?php
if ( is_front_page() && mytheme_get_featured_posts() ) {
// Include the featured content template.
get_template_part( 'content', 'featured' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment