Created
September 20, 2020 09:50
-
-
Save morvy/2addaea6a5acf3b81ecaa37bc4cb249e to your computer and use it in GitHub Desktop.
Blocksy Latest Posts - cards shortcode
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
<?php | |
function pmo_home_blog() { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) | |
return; | |
$args = array( | |
'showposts' => 3, | |
'orderby' => 'date', | |
'order' => 'DESC', | |
'post_status' => 'publish', | |
'post_type' => 'post' | |
); | |
$recent_posts = new WP_Query($args); | |
$html = '<div class="entries" data-link="type-1" data-layout="grid" data-columns="3" data-cards="boxed">'; | |
$posts = $recent_posts->posts; | |
foreach ($posts as $post) { | |
$featured_image_args = [ | |
'attachment_id' => get_post_thumbnail_id($post), | |
'ratio' => blocksy_default_akg('thumb_ratio', 'simple', '4/3'), | |
'tag_name' => 'a', | |
'size' => 'medium_large', | |
'class' => 'boundless-image', | |
'html_atts' => [ | |
'href' => esc_url(get_the_permalink($post)), | |
], | |
]; | |
$image = wp_get_attachment_url( | |
$featured_image_args['attachment_id'] | |
) ? blocksy_image($featured_image_args) : '<div class="ct-ghost"></div>'; | |
$arrow_svg = '<svg width="17px" height="17px" viewBox="0 0 32 32"><path d="M 21.1875 9.28125 L 19.78125 10.71875 L 24.0625 15 L 4 15 L 4 17 L 24.0625 17 L 19.78125 21.28125 L 21.1875 22.71875 L 27.90625 16 Z "></path></svg>'; | |
$read_more_link = '<a class="entry-button" data-type="simple" data-alignment="right" href="'.get_the_permalink( $post ).'#more-'.$post->ID.'">'.__('Read More', 'blocksy').$arrow_svg.'</a>'; | |
$html .= '<article id="post-'.$post->ID.'" class="entry-card post-'.$post->ID.' post type-post status-publish format-standard has-post-thumbnail hentry" data-reveal="yes:1">'; | |
$html .= '<h2 class="entry-title"><a style="text-decoration: none" href="'.get_the_permalink( $post ).'">'.get_the_title( $post ).'</a></h2>'; | |
$html .= $image; | |
$html .= '<div class="entry-excerpt">'.get_the_excerpt( $post ).'</div>'.$read_more_link; | |
$html .= '</article>'; | |
} | |
$html .= '</div>'; | |
wp_reset_query(); | |
return $html; | |
} | |
add_shortcode( 'blog_latest', 'pmo_home_blog' ); |
you can put it in a custom plugin, must-use plugin or in theme's functions.php file. after that, you have a shortcode available where you can use some of arguments.. in Gutenberg you choose Shortcode block and put something like this in it:
[blog_latest showposts="4"]
That's awesome... but posts are not showing in columns... one per row. How to modify that (ideally as Enhanced grid)? or how to format into grid/columns correctly
maybe you can try official shortcode:
Version: 1.7.61
RELEASED ON JANUARY 23, 2021
- Posts shortcode [blocksy_posts post_type="posts"] + supports for CPT's
maybe you can try official shortcode:
Version: 1.7.61
RELEASED ON JANUARY 23, 2021
- Posts shortcode [blocksy_posts post_type="posts"] + supports for CPT's
Yes, I saw that this morning. Correct shortcode: [blocksy_posts post_type="post"]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can put it in a custom plugin, must-use plugin or in theme's functions.php file. after that, you have a shortcode available where you can use some of arguments.. in Gutenberg you choose Shortcode block and put something like this in it:
[blog_latest showposts="4"]