Last active
August 2, 2019 05:02
-
-
Save jetsloth/89994e0c2c54c762de70cedb691c0050 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
////////////////////////////////////////////////////////////////// | |
// Latest Posts in Gravity Forms email notifications - https://jetsloth.com/labs/how-to-add-post-articles-to-your-gravity-forms-email-notifications/ | |
////////////////////////////////////////////////////////////////// | |
function custom_email_latest_posts_shortcode( $atts, $content = null ) { | |
$content = do_shortcode( shortcode_unautop( $content ) ); | |
if ( '</p>' == substr( $content, 0, 4 ) | |
&& '<p>' == substr( $content, strlen( $content ) - 3 ) ) | |
$content = substr( $content, 4, strlen( $content ) - 7 ); | |
$output = ''; | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => 4, | |
'post_status' => 'publish', | |
'fields' => 'ids' | |
); | |
$posts_query = new WP_Query($args); | |
if ($posts_query->post_count > 0): | |
ob_start(); | |
foreach($posts_query->posts as $post_id): | |
?> | |
<table width="50%" align="left" cellpadding="10"> | |
<tbody> | |
<tr> | |
<td valign="top"> | |
<a href="<?php echo get_permalink($post_id); ?>" style="width: 100%; display: inline-block; height:200px; background: url(<?php echo get_the_post_thumbnail_url($post_id, 'medium'); ?>); background-size:cover!important; background-position: center center;"></a> | |
</td> | |
</tr> | |
<tr> | |
<td align="center" valign="top"> | |
<a style="font-size: 16px; font-family: inherit; color: #ffffff; padding-bottom: 35px; padding-top:10px; text-decoration: none; line-height: 23px;" href="<?php echo get_permalink($post_id); ?>"> | |
<p><?php echo get_the_title($post_id); ?></p> | |
</a> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<?php | |
endforeach; | |
$output = ob_get_clean(); | |
endif; | |
return $output; | |
} | |
add_shortcode( 'email_latest_posts', 'custom_email_latest_posts_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment