I'm using the Gazette theme which has a jet pack enabled featured posts grid when the front page is set to show latest posts.
I would like to use a static page instead of recent posts, but keep the featured posts grid.
UPDATE
I was able to figure this out with a little moral support from the community
Link to answer - Display Featured Posts Grid on Static Page (Gazette)
Demo: /
Source: .zip
Code parts associated with the featured posts
@ index.php
<?php
if ( is_home() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
@ functions.php line 197
wp_enqueue_script( 'gazette-featured-content',
get_template_directory_uri() . '/js/featured-content.js',
array( 'jquery' ), '20150507', true );
@ featured-content.php
$featured_posts = gazette_get_featured_posts();
if ( empty( $featured_posts ) ) {
return;
}
?>
<?php
foreach ( $featured_posts as $post ) {
setup_postdata( $post );
// Include the featured content template.
get_template_part( 'content', 'featured-post' );
}
wp_reset_postdata();
?>
@ content-featured-post.php
/**
* The template for displaying featured posts on the front page
*/
<?php
// Output the featured image.
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'gazette-featured-content-thumbnail' );
}
?>
@ inc/jetpack.php line 22
add_theme_support( 'featured-content', array(
'filter' => 'gazette_get_featured_posts',
'description' => __( 'Omitted', 'gazette' ),
'max_posts' => 6,
) );
@ js/featured-content.js line 24
var featuredContent, header, primary;
featuredContent = $( '#featured-content' );
header = $( '#masthead' );
primary = $( '#primary' );
if ( ! featuredContent.length ) {
return;
}
@ js/header.js line 24
function headerStyle() {
var featuredContent, featuredContentHeight;
featuredContent = $( '#featured-content' );
featuredContentHeight = 0;
if ( featuredContent.length ) {
featuredContentHeight = featuredContent.outerHeight();
}
if ( $( '.site-branding' ).outerWidth() === 0 ) {
$( 'body' ).addClass( 'no-branding' );
} else {
$( 'body' ).removeClass( 'no-branding' );
}
These are all the references I found to the featured posts grid layout.
How can I modify to display the grid on the homepage setup as a static page?
Notes
I added this to the page.php and it does show up in the source for static, but simply does not display.
if ( is_page(35) ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
I'm using the Gazette theme which has a jet pack enabled featured posts grid when the front page is set to show latest posts.
I would like to use a static page instead of recent posts, but keep the featured posts grid.
UPDATE
I was able to figure this out with a little moral support from the community
Link to answer - Display Featured Posts Grid on Static Page (Gazette)
Demo: https://gazettedemo.wordpress/
Source: https://public-api.wordpress/rest/v1/themes/download/gazette.zip
Code parts associated with the featured posts
@ index.php
<?php
if ( is_home() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
@ functions.php line 197
wp_enqueue_script( 'gazette-featured-content',
get_template_directory_uri() . '/js/featured-content.js',
array( 'jquery' ), '20150507', true );
@ featured-content.php
$featured_posts = gazette_get_featured_posts();
if ( empty( $featured_posts ) ) {
return;
}
?>
<?php
foreach ( $featured_posts as $post ) {
setup_postdata( $post );
// Include the featured content template.
get_template_part( 'content', 'featured-post' );
}
wp_reset_postdata();
?>
@ content-featured-post.php
/**
* The template for displaying featured posts on the front page
*/
<?php
// Output the featured image.
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'gazette-featured-content-thumbnail' );
}
?>
@ inc/jetpack.php line 22
add_theme_support( 'featured-content', array(
'filter' => 'gazette_get_featured_posts',
'description' => __( 'Omitted', 'gazette' ),
'max_posts' => 6,
) );
@ js/featured-content.js line 24
var featuredContent, header, primary;
featuredContent = $( '#featured-content' );
header = $( '#masthead' );
primary = $( '#primary' );
if ( ! featuredContent.length ) {
return;
}
@ js/header.js line 24
function headerStyle() {
var featuredContent, featuredContentHeight;
featuredContent = $( '#featured-content' );
featuredContentHeight = 0;
if ( featuredContent.length ) {
featuredContentHeight = featuredContent.outerHeight();
}
if ( $( '.site-branding' ).outerWidth() === 0 ) {
$( 'body' ).addClass( 'no-branding' );
} else {
$( 'body' ).removeClass( 'no-branding' );
}
These are all the references I found to the featured posts grid layout.
How can I modify to display the grid on the homepage setup as a static page?
Notes
I added this to the page.php and it does show up in the source for static, but simply does not display.
if ( is_page(35) ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
Share
Improve this question
edited Apr 13, 2017 at 12:37
CommunityBot
1
asked Aug 19, 2016 at 14:01
Jarod ThorntonJarod Thornton
6384 silver badges18 bronze badges
2 Answers
Reset to default 1Bingo. I added the featured content template (as originally and later suggested by @user53340) to the page.php with a condition so the featured grid would only display on the page I designate.
Add to page.php
if ( is_page(ID) ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
After changing the front page display to my static page I noticed the featured content was being output in the source, however it was not showing up on the page itself.
I realized the body classes determined if this would work or not. All I had to do is add blog
to the body class for that page. The front page display sets the body class to page
for static page and blog
for posts page.
Using the code below I appended the blog
class to the body.
function add_blog_to_body_class($classes) {
$classes[] = 'blog';
return $classes;
}
add_filter('body_class','add_blog_to_body_class');
I am able to set my static page & have my featured posts grid :D
If I understand your question which is to be honest a little vague, you should be able to change if ( is_home() )
to if ( is_front_page() )
This will display the 'featured-content' template part on a static front page (i.e a home page) instead of the blog page. In Wordpress is_home
= blog home page and is_front_page
= static front page. A little confusing, but if you think WordPress was originally made for blogging, it makes perfect sense. is_home explained here is_front_page explained here
EDIT: If you want the featured grid to display everywhere, you should be able to remove the if statement so it just reads get_template_part( 'featured-content' );
that's assuming I have understood you correctly, and based on the limited code you have supplied. Hope this helps anyway.