sticky_posts = array_slice( $sticky, 0, $maxposts ); } } /** * Register hooked functions. * * @since 1.0.0 */ public static function init() { add_action( 'wp_enqueue_scripts' , array( Manta_Featured_Post::get_instance(), 'featured_scripts' ) ); add_action( 'manta_hook_on_top_of_site_content' , array( Manta_Featured_Post::get_instance(), 'render_featured_post' ) ); add_action( 'pre_get_posts' , array( Manta_Featured_Post::get_instance(), 'modify_main_query' ) ); add_filter( 'manta_get_attr_featured-content' , array( Manta_Featured_Post::get_instance(), 'style_class' ) ); } /** * Enqueue masonry scripts and styles. * * @since 1.0.0 */ public function featured_scripts() { if ( !is_home() || is_paged() ) { return; } wp_enqueue_style( 'manta_featured_style', get_template_directory_uri() . '/addon/featured/assets/manta-featured.css' ); } /** * Returns the instance. * * @since 1.0.0 * * @return object Customizer instance. */ public static function get_instance() { null === self::$instance && self::$instance = new self; return self::$instance; } /** * Display featured post. * * @since 1.0.0 */ public function render_featured_post() { if ( ! is_home() || ! $this->sticky_posts || is_paged() ) { return; } $args = array( 'ignore_sticky_posts' => 1, 'post__in' => $this->sticky_posts, ); $featured_posts = new WP_Query( $args ); $this->featured_post_count = $featured_posts->post_count; if ( $featured_posts->have_posts() ) :?> is_home() && $query->is_main_query() ) { $query->query_vars['post__not_in'] = $this->sticky_posts; } } /** * Display featured post thumbnail image. * * @since 1.0.0 * * @param array $attr attribute values array. * @return array */ public function style_class( $attr ) { if ( 2 === $this->featured_post_count ) { $attr['class'] .= ' multiple-featured-posts two-featured'; } elseif ( 3 === $this->featured_post_count ) { $attr['class'] .= ' multiple-featured-posts three-featured'; } elseif ( 4 === $this->featured_post_count ) { $attr['class'] .= ' multiple-featured-posts four-featured'; } elseif ( 5 === $this->featured_post_count ) { $attr['class'] .= ' multiple-featured-posts five-featured'; } return $attr; } } Manta_Featured_Post::init();