post_type == CPT_NEWS ): if( !has_post_thumbnail() ): $context['banner_height'] = 'page-banner--thin'; endif; $context['is_news'] = true; // Get the categories and schools for the dropdowns $context['filter'] = jb_news_get_filter_options(); // Related News $context['related_news'] = Timber::get_posts([ 'post_type' => CPT_NEWS, 'post__not_in' => [ $post->ID ], 'category__in' => array_column( $post->terms, 'term_id' ), 'orderby' => 'rand', 'numberposts' => 3, ]); if ( !is_main_site() ) { switch_to_blog( 1 ); } $context['more_updates'] = get_field('more_updates', 67); if ( ms_is_switched() ) { restore_current_blog(); } $superintendent = get_field( 'superintendent', 'district_settings' ); if( $post->post_author == $superintendent['ID'] ) : $args = []; $defaults = [ 'title_li' => false, 'echo' => false, 'child_of' => JB_DISTRICT_PAGE_ID, ]; $args = wp_parse_args( $args, $defaults ); $context['sidebar_links'] = wp_list_pages( $args ); /* Pagination within Superintendent author only */ $post_id = $post->ID; // current post ID $author = get_the_author(); $args = array( 'author' => $superintendent['ID'], 'orderby' => 'post_date', 'order' => 'DESC', ); $posts = get_posts( $args ); // get IDs of posts retrieved from get_posts $ids = array(); foreach ( $posts as $thepost ) { $ids[] = $thepost->ID; } // get and echo previous and next post in the same category $thisindex = array_search( $post_id, $ids ); $previd = isset( $ids[ $thisindex - 1 ] ) ? $ids[ $thisindex - 1 ] : false; $nextid = isset( $ids[ $thisindex + 1 ] ) ? $ids[ $thisindex + 1 ] : false; if (false !== $previd && $previd !== $post_id ) { $context['prev_url'] = get_permalink($previd); } if (false !== $nextid && $previd !== $post_id ) { $context['next_url'] = get_permalink($nextid); } $template = [ 'singles/superintendent-news.twig', 'singles/news.twig' ]; else: $template = [ 'singles/' . str_replace( '_', '-', $post->post_type ) . '.twig', 'singles/news.twig' ]; endif; endif; /* Category link for post meta */ $context['categories_url'] = '/district/news/category/'; if ( !is_main_site() ): $context['categories_url'] = '/news/category/'; endif; if ( get_field('key_contacts') ): $context['contacts'] = get_field('key_contacts'); endif; /** ** Announcements **/ $context['is_announcements'] = ( is_singular() && has_category('announcements') ? true : false ); if( has_category('announcements') ): $context['is_news'] = false; /* Pagination within announcements category only */ $post_id = $post->ID; // current post ID $cat = get_the_category(); $current_cat_id = $cat[0]->cat_ID; // current category ID $args = array( 'category' => $current_cat_id, 'orderby' => 'post_date', 'order' => 'DESC' ); $posts = get_posts( $args ); // get IDs of posts retrieved from get_posts $ids = array(); foreach ( $posts as $thepost ) { $ids[] = $thepost->ID; } // get and echo previous and next post in the same category $thisindex = array_search( $post_id, $ids ); $previd = isset( $ids[ $thisindex - 1 ] ) ? $ids[ $thisindex - 1 ] : false; $nextid = isset( $ids[ $thisindex + 1 ] ) ? $ids[ $thisindex + 1 ] : false; if (false !== $previd && $previd !== $post_id ) { $context['prev_url'] = get_permalink($previd); } if (false !== $nextid && $previd !== $post_id ) { $context['next_url'] = get_permalink($nextid); } $template = 'singles/announcement.twig'; endif; Timber::render( $template, $context );