<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Joseph Farruggio</title>
    <description>The latest articles on DEV Community by Joseph Farruggio (@joey_farruggio).</description>
    <link>https://dev.to/joey_farruggio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F82474%2Fa92437f6-74c1-4d6c-96c3-740bbbb2a5ed.jpg</url>
      <title>DEV Community: Joseph Farruggio</title>
      <link>https://dev.to/joey_farruggio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/joey_farruggio"/>
    <language>en</language>
    <item>
      <title>How to stop chatbots from killing your page speed</title>
      <dc:creator>Joseph Farruggio</dc:creator>
      <pubDate>Fri, 10 Jul 2020 13:43:27 +0000</pubDate>
      <link>https://dev.to/joey_farruggio/how-to-stop-chatbots-from-killing-your-page-speed-37h9</link>
      <guid>https://dev.to/joey_farruggio/how-to-stop-chatbots-from-killing-your-page-speed-37h9</guid>
      <description>&lt;p&gt;When we’re considering JS dependent functionality, we need to weight its benefits against its costs. Chat bots are powerful support and lead gen tools, but like any JavaScript resource it adds weight to your web page, slows TTI, and delays other resources from loading.&lt;/p&gt;

&lt;p&gt;And another thing to consider is that fact that folks don't need a chatbot the second they hit your webpage. They need a second or two to take it all in and figure out what they are going to read or click on next. So why are we forcing folks to download chatbots in a way that's not performant and doesn't serve their needs?&lt;/p&gt;

&lt;p&gt;That's why I both wrote a &lt;a href="https://joeyfarruggio.com/javascript/drift-chatbot-page-speed/"&gt;tutorial on how to optimize chatbot's for page speed&lt;/a&gt; via JavaScript and built a WordPress plugin called &lt;a href="https://chatbotspeed.com"&gt;Chatbot Lazy Loader&lt;/a&gt; to do that work for you.&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--E30tqBXJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1209658467507744769/9WXXFXe3_normal.jpg" alt="Joseph Farruggio profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Joseph Farruggio
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="comment-mentioned-user" href="https://dev.to/joey_farruggio"&gt;@joey_farruggio&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P4t6ys1m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      My very first &lt;a href="https://twitter.com/hashtag/WordPress"&gt;#WordPress&lt;/a&gt; plugin was just #1 on &lt;a href="https://twitter.com/ProductHunt"&gt;@ProductHunt&lt;/a&gt;!&lt;br&gt;&lt;br&gt;Consider taking a look and giving it an upvote.&lt;br&gt;&lt;br&gt;&lt;a href="https://t.co/LHfKQigTAd"&gt;producthunt.com/posts/chatbot-…&lt;/a&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      22:53 PM - 09 Jul 2020
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1281360928437673984" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-reply-action.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1281360928437673984" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-retweet-action.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      3
      &lt;a href="https://twitter.com/intent/like?tweet_id=1281360928437673984" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="/assets/twitter-like-action.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
      5
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;What's happening in the JavaScript is delightfully simple. Our JavaScript is delaying the download of the chatbot's JavaScript. And there's more than one way we can implement this.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We could set a timer and make the chatbot JavaScript wait 5 seconds.&lt;/li&gt;
&lt;li&gt;We could create an event listener to detect when the user begins to scroll.&lt;/li&gt;
&lt;li&gt;We could also prevent the chatbot's JavaScript from loading entirely and wait for the visitor to hover or click on a "Chat with us" button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The end result is the same though. You get to protect your page speed score and improve your visitor's experience.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>pagespeed</category>
      <category>chatbots</category>
      <category>wordpress</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Custom Post Loop as a Gutenberg Block</title>
      <dc:creator>Joseph Farruggio</dc:creator>
      <pubDate>Wed, 19 Dec 2018 05:39:02 +0000</pubDate>
      <link>https://dev.to/joey_farruggio/custom-post-loop-as-a-gutenberg-block-45k3</link>
      <guid>https://dev.to/joey_farruggio/custom-post-loop-as-a-gutenberg-block-45k3</guid>
      <description>&lt;p&gt;This post was featured in Matt Mullenweg's SOTW presentation at WCUS 2018. How cool is that?&lt;/p&gt;

&lt;p&gt;This post was originally published on &lt;a href="https://joeyfarruggio.com/wordpress/custom-post-loop-as-a-gutenberg-block/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, let's take a quick look at what we'll be building together. The image below shows the output on the front end of my customizable CPT block. In this tutorial, I'm using basic markup to output a simple and subtly styled list of testimonials, but you feel free to style it up any way you'd like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F12%2Fimage-1024x747.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F12%2Fimage-1024x747.png" alt="A custom post type testimonials block"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, in effort to spend more time and familiarize myself with Gutenberg, I wanted to convert my static front page into a Gutenberg page. One of the elements that would be handy as a block was my testimonials custom post type loop.&lt;/p&gt;

&lt;p&gt;It turns out it was pretty easy to do. There were also some controls that I added into the block editor for a small level of configuration.&lt;/p&gt;

&lt;p&gt;In my previous post I covered how to create a custom &lt;a href="https://joeyfarruggio.com/wordpress/custom-gutenberg-block-advanced-custom-fields/" rel="noopener noreferrer"&gt;Gutenberg block&lt;/a&gt; with Advanced Custom Field’s &lt;strong&gt;acf_register_block().&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the time of this tutorial, Gutenberg has not yet been added into core, so we’ll need the Gutenberg plugin. We’ll also need the beta version of ACF Pro, which is currently 5.8.0 Beta. To quickly prototype my testimonial template, I'm using Tailwind.css. You'll notice the use of utility classes in my markup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://advancedcustomfields.com/" rel="noopener noreferrer"&gt;Advanced Custom Fields&lt;/a&gt; – 5.8.0 Beta&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://wordpress.org/plugins/gutenberg/" rel="noopener noreferrer"&gt;Gutenberg plugin&lt;/a&gt; or update to WordPress 5.0+&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tailwindcss.com" rel="noopener noreferrer"&gt;Tailwind.css&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up the CPT
&lt;/h2&gt;

&lt;p&gt;I use the free &lt;a href="https://wordpress.org/plugins/custom-post-type-ui/" rel="noopener noreferrer"&gt;CPT UI&lt;/a&gt; plugin for quickly setting up custom post types.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-10.png" alt="Setting up a custom post type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this CPT, I want to mainly  use custom fields. So that means no classic editor or Gutenberg. In order to disable Gutenberg on CPT you need to set the “Show in REST API” to false. Set it to true if you do want to use the Gutenberg editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-11.png" alt="Enabling the REST API"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Custom Fields
&lt;/h2&gt;

&lt;p&gt;Within Advanced Custom Fields I created just two fields for the testimonial; the author’s title and the quote. I’ll use the post title for the author’s name and the feature image for the author’s profile image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-12.png" alt="Creating the post loop custom fields with ACF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Register the Testimonial Block
&lt;/h2&gt;

&lt;p&gt;Within our functions.php file we’ll register our testimonial block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;functions.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Register Custom Blocks&lt;/span&gt;
&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'acf/init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'my_acf_init'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;my_acf_init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// check function exists&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'acf_register_block'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// register a testimonials block&lt;/span&gt;
        &lt;span class="nf"&gt;acf_register_block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s1"&gt;'name'&lt;/span&gt;              &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'testimonials'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'title'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Testimonials'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wprig'&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'description'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'A custom testimonial block.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wprig'&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'render_callback'&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'my_acf_block_render_callback'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'category'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'formatting'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'icon'&lt;/span&gt;              &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'admin-comments'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'keywords'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'testimonial'&lt;/span&gt; &lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="c1"&gt;// register other blocks&lt;/span&gt;
        &lt;span class="nf"&gt;acf_register_block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="mf"&gt;...&lt;/span&gt;
        &lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create the Testimonial Block Fields
&lt;/h2&gt;

&lt;p&gt;I want some level of configuration over my testimonial block. Depending on where I use it, I’ll want to either loop testimonials with a ‘posts_per_page’ to set a limit or I’ll want to hand select which testimonials to display.&lt;/p&gt;

&lt;p&gt;Back in Advanced Custom Fields we’ll create three fields to create this functionality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-13.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-13.png" alt="Creating the block controls custom fields"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this field group I’ve created a button group to allow the user to select between limiting the post loop with a number or selecting from a list of published testimonials.&lt;/p&gt;

&lt;p&gt;Both the ‘Testimonial Count’ and ‘Select Testimonials’ fields have a conditional argument to only be displayed based on the selection of the ‘Loop Argument Type’.&lt;/p&gt;

&lt;p&gt;The Select Testimonials Post Object field should be set to return just the post ID.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the Testimonial Template
&lt;/h2&gt;

&lt;p&gt;Within template-parts/blocks/content-testimonials.php I’ll create my template and add some Php to dynamically set the argument type in the loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;template-parts/blocks/content-testimonials.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="cd"&gt;/**
 * Block Name: Testimonials
 *
 * This is the template that displays the testimonials loop block.
 */&lt;/span&gt;

&lt;span class="nv"&gt;$argType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'loop_argument_type'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$argType&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"count"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;
  &lt;span class="nv"&gt;$args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; 
    &lt;span class="s1"&gt;'orderby'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'post_type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'testimonials'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'posts_per_page'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;get_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'testimonial_count'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
  &lt;span class="nv"&gt;$testimonials&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'select_testimonials'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nv"&gt;$args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; 
    &lt;span class="s1"&gt;'orderby'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'post_type'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'testimonials'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'post__in'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$testimonials&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;endif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$the_query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WP_Query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$args&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I’ll start the loop and populate our testimonial fields in the template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;template-parts/blocks/content-testimonials.php&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c1"&gt;// Continued code&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$the_query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;have_posts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$the_query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;have_posts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$the_query&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;the_post&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"rounded border-b border-solid border-grey-lighter px-6 py-4 mb-2 max-w-md"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex items-center"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;get_the_post_thumbnail_url&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"h-12 w-12 rounded-full"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex flex-col ml-4"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;b&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"font-bold text-black"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nf"&gt;the_title&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/b&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-grey"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;get_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'authors_title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get_the_ID&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;" mt-3 mb-1 leading-normal text-base"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;get_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'quote'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get_the_ID&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;endwhile&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Sorry, there are no testimonials to display'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wprig'&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="k"&gt;endif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There’s one thing that I need to point out here to save you from some frustration. When looping through posts in a Gutenberg block, you must add the post ID as the second parameter when using ‘get_field()’.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting the Post ID as a second parameter&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;get_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'quote'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get_the_ID&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using the Testimonial Block
&lt;/h2&gt;

&lt;p&gt;I want to add testimonials to my home page, so within the editor I added a testimonial block. I set the Loop Argument Type to Count and then set the Testimonial Count to 3.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-14.png" alt="Using the new CPT block"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If I wanted to hand pick which testimonials I wanted to display, I could set the Loop Argument Type to Select Posts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-15.png" alt="Selecting specific posts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a multi-select field, so I could add as many as I'd like.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fjoeyfarruggio.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fimage-16.png" alt="A list of testimonials on the front end"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there we have it! Our custom post type is looped and applied to a custom template which is configurable and reusable as a block throughout any post or page.&lt;/p&gt;

&lt;p&gt;-- &lt;/p&gt;

&lt;h2&gt;
  
  
  Selfish Sales Plug Alert
&lt;/h2&gt;

&lt;p&gt;Want to hire me to build you a custom Gutenberg block for your Gutenberg enabled theme?&lt;/p&gt;

&lt;p&gt;Interested in finding out if your WordPress theme is ready and compatible with Gutenberg? &lt;/p&gt;

&lt;p&gt;Say hello to me at &lt;a href="mailto:joey@joeyfarruggio.com"&gt;joey@joeyfarruggio.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>gutenberg</category>
      <category>acf</category>
      <category>advancedcustomfields</category>
    </item>
  </channel>
</rss>
