diff --git a/index.php b/index.php index 53bb41a46b..b59acd4379 100755 --- a/index.php +++ b/index.php @@ -20,6 +20,7 @@ use Timber\Timber; $context = Timber::get_context(); +$posts = Timber::get_posts(); $templates = [ 'index.twig' ]; if (is_home()) { @@ -33,7 +34,6 @@ $context['title'] = ( $page_meta_data['p4_title'] ?? '' ) ? ( $page_meta_data['p4_title'] ?? '' ) : html_entity_decode($context['wp_title'] ?? ''); - $context['posts'] = Timber::get_posts(); Context::set_header($context, $page_meta_data, $context['title']); Context::set_background_image($context); @@ -41,6 +41,27 @@ Context::set_campaign_datalayer($context, $page_meta_data); Context::set_utm_params($context, $post); + $MIN_STICKY_POSTS = 4; + $sticky_posts = array_filter($posts, function ($p) { + if(is_sticky($p->ID)) { + // echo $p->ID . ""; + return $p; + } + }); + + if(count($sticky_posts) > $MIN_STICKY_POSTS) { + $posts = array_filter($posts, function ($p) { + if(!is_sticky($p->ID)) { + return $p; + } + }); + } else { + $sticky_posts = array(); + } + + $context['posts'] = $posts; + $context['sticky_posts'] = $sticky_posts; + array_unshift($templates, 'all-posts.twig'); $page = new ListingPage($templates, $context); diff --git a/templates/featured-posts.twig b/templates/featured-posts.twig new file mode 100644 index 0000000000..704fe61580 --- /dev/null +++ b/templates/featured-posts.twig @@ -0,0 +1 @@ +