Skip to content

Instantly share code, notes, and snippets.

@BiancaNL
Created September 27, 2021 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BiancaNL/b115b398fb5e52444bb9a8b5c4622489 to your computer and use it in GitHub Desktop.
Save BiancaNL/b115b398fb5e52444bb9a8b5c4622489 to your computer and use it in GitHub Desktop.
Frost Dynamic Posts with Genesis Custom Blocks
<?php
//Variables
$number_of_posts = block_value( 'post-amount' );
$category = block_value( 'category' );
// The Query
$the_query = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => $number_of_posts,
'category_name' => $category->name
)
);
// The Loop
if ($the_query->have_posts()) {
echo '<hr class="wp-block-separator is-style-wide"/>';
while ($the_query->have_posts()) {
$the_query->the_post();
// Variables
$categories = get_the_category();
$first_cat = $categories[0]->name;
$first_cat_url = get_category_link( $categories[0]->term_id );
?>
<div class="wp-block-columns are-vertically-aligned-center">
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:25%">
<p class="has-small-font-size"><?php echo get_the_date('M d, Y'); ?></p>
</div>
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:50%">
<p class="has-small-font-size"><?php the_title(); ?></p>
</div>
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:25%">
<div class="wp-block-buttons is-content-justification-right">
<div class="wp-block-button is-style-small"><a class="wp-block-button__link no-border-radius" href="<?php the_permalink(); ?>">Read Article →</a></div>
</div>
</div>
</div>
<hr class="wp-block-separator is-style-wide"/>
<?php
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
?>
@BiancaNL
Copy link
Author

BiancaNL commented Sep 27, 2021

This file needs to be posted in the (Frost)theme folder with the following path: blocks/posts-block. See Genesis Custom Blocks for further information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment