Created
April 1, 2018 01:19
-
-
Save TanvirAmi/b21f65d8f7d53801ecfed616a2dbe1c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Featured post child function | |
function rexus_featured_posts() { | |
global $post; | |
$enable = of_get_option( 'rexus_enable_featured', '1' ); // Enable disable area. | |
$tag = of_get_option( 'rexus_featured_tag' ); // Get the user selected tag for the featured posts. | |
// Bail if disable by user. | |
if ( ! $enable ) { | |
return; | |
} | |
// Get any existing copy of our transient data. | |
if ( false === ( $featured = get_transient( 'rexus_featured_posts' ) ) ) { | |
// It wasn't there, so regenerate the data and save the transient. | |
// Posts query arguments. | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => 7 | |
); | |
if ( ! empty( $tag ) ) { | |
$args['tag_id'] = $tag; | |
} | |
// The post query | |
$featured = get_posts( $args ); | |
// Store the transient. | |
set_transient( 'rexus_featured_posts', $featured ); | |
} | |
// Check if the post(s) exist. | |
if ( $featured ) : | |
$html = '<section id="featured-content" class="clearfix">'; | |
$html .= '<section id="featured-content" class="clearfix">'; | |
$i = 0; | |
$class = ''; | |
$thumbsize = ''; | |
foreach ( $featured as $post ) : | |
setup_postdata( $post ); | |
if ( $i % 4 ) { | |
$class = 'featured-small'; | |
$thumbsize = 'rexus-featured-thumb-s'; | |
} else { | |
$class = 'featured-big'; | |
$thumbsize = 'rexus-featured-thumb'; | |
} | |
$html .= '<div id="featured-' . $i . '" class="featured-box featured-' . $i . ' ' . $class. ' gradient gradient-' . $i . '">'; | |
$html .= '<a href="' . get_permalink( $post->ID ) . '" rel="bookmark" target="__blank">'; | |
if ( has_post_thumbnail( $post->ID ) ) { | |
$html .= get_the_post_thumbnail( $post->ID, $thumbsize, array( 'class' => 'entry-thumbnail', 'alt' => esc_attr( get_the_title( $post->ID ) ) ) ); | |
} | |
$html .= '<div class="entry-header gradient-tran-white"><h2 class="entry-title">' . get_the_title( $post->ID ) . '</h2></div>'; | |
$html .= '</a>'; | |
$html .= '</div>'; | |
$i++; | |
endforeach; | |
$html .= '</section>'; | |
$html .= '</section><!-- #featured-content -->'; | |
// End check. | |
endif; | |
// Restore original Post Data. | |
wp_reset_postdata(); | |
// Display the posts. | |
if ( ! empty( $html ) ) { | |
echo $html; | |
} | |
} | |
//Breaking news child function | |
function rexus_breaking_news() { | |
global $post; | |
$enable = of_get_option( 'rexus_enable_breaking', '1' ); // Enable disable area. | |
$tag = of_get_option( 'rexus_breaking_tag' ); // Get the user selected tag for the breaking news posts. | |
$num = of_get_option( 'rexus_breaking_num', 10 ); // Get the number of posts to show. | |
// Bail if disable by user. | |
if ( ! $enable ) { | |
return; | |
} | |
// Return early if on single post. | |
if ( is_single() ) { | |
return; | |
} | |
// Get any existing copy of our transient data. | |
if ( false === ( $breaking = get_transient( 'rexus_breaking_posts' ) ) ) { | |
// It wasn't there, so regenerate the data and save the transient. | |
// Posts query arguments. | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => absint( $num ) | |
); | |
if ( ! empty( $tag ) ) { | |
$args['tag_id'] = $tag; | |
} | |
// The post query | |
$breaking = get_posts( $args ); | |
// Store the transient. | |
set_transient( 'rexus_breaking_posts', $breaking ); | |
} | |
// Check if the post(s) exist. | |
if ( $breaking ) : | |
$html = '<section id="breaking-news">'; | |
$html .= '<ul id="js-news" class="js-hidden">'; | |
foreach ( $breaking as $post ) : | |
setup_postdata( $post ); | |
$html .= '<li class="newst-item">'; | |
$html .= '<a href="' . get_permalink( $post->ID ) . '" rel="bookmark" target="__blank">' . esc_attr( get_the_title( $post->ID ) ) . '</a>'; | |
$html .= '</li>'; | |
endforeach; | |
$html .= '</ul>'; | |
$html .= '</section><!-- #breaking-news -->'; | |
// End check. | |
endif; | |
// Restore original Post Data. | |
wp_reset_postdata(); | |
// Display the posts. | |
if ( ! empty( $html ) ) { | |
echo $html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment