Created
August 18, 2017 03:54
-
-
Save anonymous/cf6239d57c08291dbc09656d35601cd9 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
function education_hub_get_home_news_block_content() { | |
$home_news_section_status = education_hub_get_option( 'home_news_section_status' ); | |
if ( true !== $home_news_section_status ) { | |
return; | |
} | |
$home_news_section_title = education_hub_get_option( 'home_news_section_title' ); | |
$home_news_category = education_hub_get_option( 'home_news_category' ); | |
$home_news_number = education_hub_get_option( 'home_news_number' ); | |
$home_news_excerpt_length = education_hub_get_option( 'home_news_excerpt_length' ); | |
$home_news_read_more_text = education_hub_get_option( 'home_news_read_more_text' ); | |
$qargs = array( | |
'posts_per_page' => absint( $home_news_number ), | |
'no_found_rows' => true, | |
'post_type' => 'post', | |
); | |
if ( absint( $home_news_category ) > 0 ) { | |
$qargs['category'] = absint( $home_news_category ); | |
} | |
$all_posts = get_posts( $qargs ); | |
ob_start(); | |
?> | |
<?php if ( ! empty( $all_posts ) ) : ?> | |
<div class="recent-news"> | |
<h2><?php echo esc_html( $home_news_section_title ); ?></h2> | |
<?php global $post; ?> | |
<div class="inner-wrapper"> | |
<?php foreach ( $all_posts as $post ) : ?> | |
<?php setup_postdata( $post ); ?> | |
<div class="news-post"> | |
<?php if (has_post_thumbnail() ): ?> | |
<a href="<?php the_permalink(); ?> " ><?php the_post_thumbnail( 'education-hub-thumb', array( 'class' => 'aligncenter' ) ); ?></a> | |
<?php endif ?> | |
<div class="news-content"> | |
<h3><a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></h3> | |
<div class="block-meta"> | |
<?php | |
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; | |
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { | |
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; | |
} | |
$time_string = sprintf( $time_string, | |
esc_attr( get_the_date( 'c' ) ), | |
esc_html( get_the_date() ), | |
esc_attr( get_the_modified_date( 'c' ) ), | |
esc_html( get_the_modified_date() ) | |
); | |
echo $posted_on = sprintf( | |
'%s', | |
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>' | |
); | |
?> | |
</div> | |
<?php if ( absint( $home_news_excerpt_length ) > 0 ): ?> | |
<?php | |
$excerpt = education_hub_the_excerpt( absint( $home_news_excerpt_length ), $post ); | |
//echo wp_kses_post( wpautop( $excerpt ) ); | |
?> | |
<?php endif ?> | |
<?php if ( ! empty( $home_news_read_more_text ) ): ?> | |
<a href="<?php the_permalink(); ?>" target="_blank" class="button"><?php echo esc_html( $home_news_read_more_text ); ?></a> | |
<?php endif ?> | |
</div> <!-- .news-content --> | |
</div> <!-- .news-post --> | |
<?php endforeach ?> | |
</div> <!-- .inner-wrapper --> | |
<?php wp_reset_postdata(); ?> | |
</div> <!-- .recent-news --> | |
<?php endif; ?> | |
<?php | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment