Created
May 16, 2024 13:34
-
-
Save Archie22is/780cbf31f979f581cdfd6851d0821fb7 to your computer and use it in GitHub Desktop.
Working example of a WordPress Loop Shortcode
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 (!function_exists('footer_get_latest_post')) { | |
function footer_get_latest_post() { | |
ob_start(); | |
$footerPost = ''; | |
$args = array('posts_per_page' => 1 ); | |
$recent_posts = new WP_Query($args); | |
while( $recent_posts->have_posts() ) { | |
$recent_posts->the_post(); | |
$footerPost = '<div class="footer-post-thumb">' . the_post_thumbnail('thumbnail') . '</div>'; | |
$footerPost .= '<div class="footer-post-content"><h3>' . the_title() . '</h3>'; | |
$footerPost .= the_content() . '</div>'; | |
} | |
wp_reset_query(); | |
//return $footerPost; | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
return $output; | |
} | |
} | |
add_shortcode('FooterLatestPost', 'footer_get_latest_post'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment