-
-
Save iamtekeste/e595c0d0ba940d273ede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$news_term = get_term_by('name', 'news', 'category'); | |
if(!empty($news_term)) { | |
$news_child_terms = get_categories(array( | |
'parent' => $news_term->term_id | |
)); | |
$features_news_terms = get_terms(array('category'),array( | |
'slug' => 'featured', | |
'parent' => $news_term->term_id | |
)); | |
if(!empty($features_news_terms)) { | |
$featured_news_term = $features_news_terms[0]; | |
//get list of featured news (2) | |
$featured_news_query = new WP_Query(array( | |
'cat' => $featured_news_term->term_id, | |
'posts_per_page' => 2, | |
'orderby' => 'post_date', | |
'order' => 'DESC', | |
)); | |
} | |
} | |
//get latest featured news | |
//get latest news (excluding featured news) | |
?> | |
<?php if(!empty($news_term)): ?> | |
<div class="row content-section"> | |
<h2 class="col-md-12 section-heading"><?php echo $news_term->name; ?></h2> | |
<div class="col-md-12"> | |
<div class="row"> | |
<!-- NEWS 1 --> | |
<?php $featured_news_ids = array(); ?> | |
<?php if(!empty($featured_news_term)): ?> | |
<?php while($featured_news_query->have_posts()): | |
$featured_news_query->the_post(); | |
$featured_news_ids[] = get_the_ID(); ?> | |
<div class="col-sm-6 col-md-4 news-item"> | |
<a href="<?php echo the_permalink(); ?>" class="thumb"> | |
<img src="<?php echo get_template_directory_uri(); ?>/assets/img/news-img-1.jpg" /> | |
</a> | |
<div class="detail"> | |
<a class="tag"><?php echo agri_get_post_terms_no_link_string('category'); ?></a> | |
<span class="date"><?php echo get_the_date('F d, Y'); ?></span> | |
<a class="title" href="<?php echo the_permalink(); ?>" ><?php the_title(); ?></a> | |
<div class="content"><?php the_advanced_excerpt('length=80&length_type=characters'); ?></div> | |
<a href="<?php echo the_permalink(); ?>" class="read-more">Read more <span class="icon-more-arrow"></span></a> | |
</div> | |
</div> | |
<?php endwhile; ?> | |
<?php endif; ?> | |
<?php | |
//get list of latest news (4) | |
$latest_news_query = new WP_Query(array( | |
'cat' => $news_term->term_id, | |
'posts_per_page' => 4, | |
'post__not_in' => $featured_news_ids, //make sure to exclude featured news to avoid repetition | |
'orderby' => 'post_date', | |
'order' => 'DESC', | |
)); | |
?> | |
<?php if($latest_news_query->have_posts()): ?> | |
<!-- NEWS LISTING --> | |
<div class="col-md-4 news-list-items"> | |
<?php while($latest_news_query->have_posts()): $latest_news_query->the_post(); ?> | |
<div class="news-item"> | |
<div class="detail"> | |
<a class="tag"><?php echo agri_get_post_terms_no_link_string('category'); ?></a> | |
<span class="date"><?php echo get_the_date('F d, Y'); ?></span> | |
<a class="title" href="<?php echo the_permalink(); ?>" ><?php the_title(); ?></a> | |
<div class="content"><?php the_advanced_excerpt('length=80&length_type=characters'); ?></div> | |
<a href="<?php echo the_permalink(); ?>" class="read-more">Read more <span class="icon-more-arrow"></span></a> | |
</div> | |
</div> | |
<?php endwhile; ?> | |
<a class="read-more" href="/news">More News <span class="icon-more-arrow"></span></a> | |
</div> | |
<?php endif; ?> | |
</div> | |
</div> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment