name; } $post_arr['url'] = get_permalink( $post_id ); $post_arr['content'] = get_the_excerpt( $post_id ); array_push( self::$data_arr, $post_arr ); } return apply_filters( 'octane_news_post_data_arr', self::$data_arr ); } public static function render_from_page() { $news_pages = Octane_Theme_Options::get_option( 'homepage-news-page-repeater' ); foreach ( $news_pages as $news ) { $page_id = absint( $news['page'] ); $page_arr['title'] = get_the_title( $page_id ); $page_arr['img'] = get_the_post_thumbnail( $page_id ); $page_arr['date'] = get_the_date( get_option( 'date_format' ), $page_id ); $page_arr['url'] = get_permalink( $page_id ); $page_arr['content'] = get_the_content( null, false, $page_id ); array_push( self::$data_arr, $page_arr ); } return apply_filters( 'octane_news_page_data_arr', self::$data_arr ); } public static function render_from_category() { $news_cat = Octane_Theme_Options::get_option( 'homepage-news-category' ); $cat_query = new WP_Query( array( 'post_type' => 'post', 'ignore_sticky_posts' => true, 'cat' => absint( $news_cat ), 'posts_per_page' => 999, ) ); $post_merging_arr = []; $news_cat_content = Octane_Theme_Options::get_option( 'homepage-news-cat-repeater' ); foreach ( $news_cat_content as $news ) { array_push( $post_merging_arr, $post_content ); } // Defining a new array to be merged later // Since there are two loops, the result of two loops will have double arrays to be merged, it is defined such that the data in this array will be merged with later formed array and structure will be like that of previous ones. $i = 0; while ( $cat_query->have_posts() ): $cat_query->the_post(); $post_id = get_the_ID(); $post_arr['title'] = get_the_title(); $post_arr['img'] = get_the_post_thumbnail(); $post_arr['cat'] = get_cat_name( absint( $news_cat ) ); $post_arr['date'] = get_the_date( get_option( 'date_format' ), $post_id ); $post_arr['url'] = get_permalink(); $post_arr['content'] = get_the_excerpt( $post_id ); if ( ! empty( $post_merging_arr[$i] ) ) { $post_merged_arr = array_merge( $post_merging_arr[ $i ], $post_arr ); array_push( self::$data_arr, $post_merged_arr ); } else { array_push( self::$data_arr, $post_arr ); } $i++; endwhile; wp_reset_postdata(); return apply_filters( 'octane_news_category_data_arr', self::$data_arr ); } public static function render_content() { $news_enable = Octane_Theme_Options::get_option( 'homepage-news-enable' ); if ( ! $news_enable ) { return; } $title = Octane_Theme_Options::get_option( 'homepage-news-title' ); $news_btn_txt = esc_html__( 'View More', 'octane' ); $news_btn_url = Octane_Theme_Options::get_option( 'homepage-news-btn-url' ); $content_layout = [ 'image', 'content' ]; $columns = 4; $news_content = Octane_Theme_Options::get_option( 'homepage-news-content' ); if ( 'post' === $news_content ) { $data_arr = self::render_data( self::render_from_post() ); } elseif ( 'page' === $news_content ) { $data_arr = self::render_data( self::render_from_page() ); } elseif ( 'category' === $news_content ) { $data_arr = self::render_data( self::render_from_category() ); } elseif ( 'custom' === $news_content ) { $data_arr = self::render_data( self::render_from_custom() ); } ?>