Last active
October 1, 2020 12:50
-
-
Save Pavracer/571f7a4a5a4db41f9ae2f1f8ef94fa19 to your computer and use it in GitHub Desktop.
Extra Trending post change to Latest
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
<?php $args = array( | |
'numberposts' => '1', | |
); | |
$recent_posts = wp_get_recent_posts( $args ); | |
foreach( $recent_posts as $recent ): | |
$post_id = $recent['ID']; | |
$post_url = get_permalink($recent['ID']); | |
$post_title = $recent['post_title']; | |
$post_content = $recent['post_content']; | |
$post_thumbnail = get_the_post_thumbnail($recent['ID']); | |
endforeach; | |
echo '<div class="et-trending-post et-trending-latest"><a href="'.$post_url.'">'.$post_title.'</a></div>'; | |
?> |
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
<?php if ( $header_vars['trending_posts']->have_posts() ) : ?> | |
<?php | |
$trending_post_count = 0; | |
while ( $header_vars['trending_posts']->have_posts() ) : $header_vars['trending_posts']->the_post(); | |
$trending_post_latest_class = $trending_post_count == 0 ? 'et-trending-latest' : ''; | |
$trending_post_classes = extra_classes( array( 'et-trending-post', $trending_post_latest_class ), 'et-trending-post', false ); | |
?> | |
<div id="et-trending-post-<?php the_ID(); ?>" class="<?php echo esc_attr( $trending_post_classes ); ?>"> | |
<a href="<?php the_permalink(); ?>"><?php echo esc_html( truncate_title( 55 ) ); ?></a> | |
</div> | |
<?php | |
$trending_post_count++; | |
endwhile; | |
wp_reset_postdata(); | |
?> | |
<?php else : ?> | |
<div id="et-trending-post-sample" class="et-trending-post et-trending-latest"> | |
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php esc_html_e( 'Sample Post Title', 'extra' ); ?></a> | |
</div> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wondering, can this code be used in a Divi Child theme? If so, where is it dropped, in the functions.php? Is there are shortcode that can be used to insert it into a Divi Text module?