<?php
/**
* Block Name: Client Testimonials
*
* Block for Client Testimonials.
*/
// create id attribute for specific styling
$id = $block['id'];
?>
<div class="client-testimonial">
// The following the_field value come from a field that is entered on the page where we are placing this block.
<h3><?php the_field('title');?></h3>
<?php $args = array('post_type' => "testimonials", 'posts_per_page' => 1, 'orderby'=>"rand", 'order'=>"asc");
$postType = new WP_Query( $args );
if( $postType->have_posts() ) {
while( $postType->have_posts() ) {
$postType->the_post();
?>
<div class="quote">
// The echo get_field below is within the testimonial loop that is part of our Gutenberg Block built with ACF notice we have to sue echo get_field and add the additional get_the_ID() to pull from our Custom Post Type Loop
<h4><?php echo get_field( 'quote_title', get_the_ID() ); ?></h4>
<span class="small-border"></span>
<div class="main-content partial-width big-quote"><?php the_content();?></div>
<div class="author-name"><?php echo get_field( 'author_name', get_the_ID() ); ?></div>
</div>
<?php
}
}
wp_reset_query();
?>
</div>
Sample Gutenberg block built with ACF. For this example we are pulling a random testimonial from a Custom Post Type. For that CPT we have two fields a quote_title and author_name. We have to use <?php echo get_field( 'quote_title', get_the_ID() ); ?> to pull from fields within a loop that we are incorporating as a Gutenberg.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.