Easiest Way To Create A Dynamic WordPress Block (Gutenberg Development Tutorial)

Sdílet
Vložit
  • čas přidán 24. 06. 2019
  • In this tutorial, we go over how to create a Dynamic WordPress Block using create-guten-block, React, and PHP. Gutenberg can be confusing, so hopefully, this video will help you with getting started in your block development!
    Sign up for the newsletter to notified about the free 2020 WordPress Development Course: wpcasts.tv
    Get WordPress Hosting:
    wpcasts.tv/go/kinsta
    *Don't forget to subscribe!*
    *SOCIAL*
    Twitter: / alexanderbyoung
    Instagram: / the_alex_young
    #WordPress #Gutenberg #React

Komentáře • 72

  • @WPCasts
    @WPCasts  Před 5 lety +5

    I hope you learned something! Gutenberg has been especially mysterious to me, so I wanted to distill what I've learned into a quick tutorial.
    Follow me on Twitter so we can chat! - twitter.com/_WPCasts_tv_

  • @artabramov2254
    @artabramov2254 Před 4 lety +1

    Great tutorial, Alex, thank you a lot! Gutenberg seemed a very strange and useless thing for me when it only arrived but now when I explore it more and more I really start liking Gutenberg. It has a great power and what I like the most it could help to build sites with less bloat in the code than page builders

  • @gggfff7675
    @gggfff7675 Před 5 lety

    Thanks a lot! I think you has gone deeper than anyone on youtube! 👍 Great job!

  • @escuelawordpress1308
    @escuelawordpress1308 Před 5 lety

    Simply amazing intro to block creation with WP Gunteberg! Thanks!

  • @andreranulfo-dev8607
    @andreranulfo-dev8607 Před 8 měsíci

    15:14 That's what was giving me headaches! Thanks!

  • @antoineoriot5538
    @antoineoriot5538 Před 2 lety

    Great tutorial, thank you exactly what I was looking for !

  • @JustinTiell
    @JustinTiell Před 2 lety

    This is exactly what I needed! Great video!

  • @travholt
    @travholt Před 5 lety

    Nice! I haven't gotten around to using Gutenberg much, but this was very instructional. Thanks.

    • @WPCasts
      @WPCasts  Před 5 lety

      I'm glad you found it instructional! Cheers!

  • @dimor22
    @dimor22 Před 4 lety

    Yes it was very helpful, I learned a lot. Thank you

  • @danihazler
    @danihazler Před 4 lety

    This tutorial is so helpful! Thanks a lot!

  •  Před 3 lety

    Awesome tutorial! I would love to see a version while using React and creating the whole structure from scratch.

  • @zipponvr7043
    @zipponvr7043 Před 3 lety

    Definitely LIKE
    You're the best, very good tutorial!

  • @rayremnant
    @rayremnant Před 5 lety +3

    Hi, thank you for this eye-opening tutorial, really what I was looking for. Can you make a github repository with the code? That would be amazing! Anyway, thank you for making this, luv u Alex

  • @andreranulfo-dev8607
    @andreranulfo-dev8607 Před 8 měsíci

    Just Priceless!

  • @user-en8fd9ut5q
    @user-en8fd9ut5q Před 3 lety

    Great lesson. Good luck!

  • @rovshen.public
    @rovshen.public Před 4 lety

    Thank you so much! For this video!

  • @nitdesign
    @nitdesign Před 4 lety +1

    Thanks for the tutorial. I'd like to know how to improve this front-end side, implementing for example a "load more" functionality and filter para category or taxonomy. Any suggestion on tutorials that cover these functionalities? Many thanks!

  • @qoraicheyassine6452
    @qoraicheyassine6452 Před 3 lety

    Thanks for this

  • @oguz-kagan
    @oguz-kagan Před 4 lety

    thank you really helpful

  • @miguelmachado6862
    @miguelmachado6862 Před 5 lety +1

    Great work. Today did the same but using ACF Blocks. I think that is a simple solution for people like me that use ACF, using their php framework

    • @WPCasts
      @WPCasts  Před 5 lety +1

      I love ACF's block interface. I should do a video on those. The only downside is that it's behind the pro version...but man is it a worth the $.

    • @miguelmachado6862
      @miguelmachado6862 Před 5 lety

      WPCasts true, it’s a must have for every Wordpress developer. Keep the good work ;)

  • @nateandersson
    @nateandersson Před 3 lety

    Tip! If you want a preview in admin include the ServerSideRender component from wp.components, and add

  • @pahtashow
    @pahtashow Před 4 lety

    A full course on wordpress development please!

  • @MatthewMcDonald
    @MatthewMcDonald Před 3 lety

    Super!

  • @MorganHvidt
    @MorganHvidt Před 5 lety

    Thank you for this tutorial! I subscribed 😄
    I'm wondering if you'll continue with adding the category selector and posts per page options into the sidebar. That would allow the block to be used as a preview of the posts. What do you think?

    • @WPCasts
      @WPCasts  Před 5 lety +2

      I think that's a great idea. I'm still deciding how deep into Gutenberg I want to go. If I go deep, I'll definitely cover settings in the sidebar.

    • @MorganHvidt
      @MorganHvidt Před 5 lety

      @@WPCasts I hope you do, it was a joy to follow :)

  • @lloydmangin2335
    @lloydmangin2335 Před rokem

    Hi Alex, do you have a repo for this tutorial? thanks

  • @oliviaposch187
    @oliviaposch187 Před 2 lety

    Hi @WPCast thanks for the Tutorial
    I follow it, but the settings to display the posts on the frontend does not work....

  • @LeandroBergSchulz
    @LeandroBergSchulz Před 4 lety +1

    Hello, nice tutorial, thanks. Can you please give me a little explanation why you have been used apiFetch instead of getEntityRecords like Block Handbook examples at dynamic blocks tutorial?

  • @devnebula
    @devnebula Před 4 lety +1

    If you want to get the data slightly easily use wp.data .select('core').getEntityRecords('postType', 'post');
    wp.data .select('core').getEntityRecords('taxonomy', 'category');

    • @junglized
      @junglized Před 4 lety

      I'm getting list of posts with wp.data.select('core').getEntityRecords('postType', 'post'); but null with wp.data.select('core').getEntityRecords('taxonomy', 'category'); when I try to consloe.log it. Any ideas?

  • @renanbessa8778
    @renanbessa8778 Před 3 lety

    Is there anyway to render the content for edit() method from the server side? Just like return null and render_callback similar to save()?

  • @sandeepjainwp
    @sandeepjainwp Před rokem

    Some time starting command not worked, so can use nvm use 14.16.1 before run cgb command

  • @errorerror1337
    @errorerror1337 Před 5 lety

    Got her from Reddit, great tutorial! I haven't touched Gutenberg either and this makes it look easy, even gives me hope I may pick up some modern JavaScript!

    • @WPCasts
      @WPCasts  Před 5 lety

      You can and should! Thanks for the feedback :)

  • @jannemanhuman4237
    @jannemanhuman4237 Před 2 lety

    I enjoyed the video thanks. I followed it and it works when you want to select a single category. However, what about a multi-select? How would you handle that?

    • @thenajsays
      @thenajsays Před 2 lety +1

      its very easy, for the 'select' element, after the 'value' attribute, add 'multiple' and thats it.

  • @mostafamrabet7883
    @mostafamrabet7883 Před 4 lety

    Hi thanks for this tuto it really helps! but i got an error : react-dom.min.js?ver=16.9.0:103 TypeError: Failed to construct 'Option': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
    I use wordpress v.5.3.2 php: 7.3.12. thanks.

  • @antonfsd
    @antonfsd Před 3 lety +1

    great explanation! one question: does this mean we can only do one dynamic block in the instance of create-guten-block? sometimes for static blocks I'll create a handful in one create-guten-block folder and just import them all in the blocks.js file under src, but I assume since there is only one render callback we'd need to seperate it out for dynamic. Is it bad practice to have several statics in the same place too?

    • @dragos199993
      @dragos199993 Před 3 lety +1

      nope, take a look here: github.com/ahmadawais/create-guten-block/tree/master/examples/03-multi-block

  • @diederickb1806
    @diederickb1806 Před 2 lety +1

    create-guten-block is broken for me ;c can u redo this tutorial using the new npm init @wordpress/block?

  • @carlosg8716
    @carlosg8716 Před 5 lety

    I created my block and it works fine in localhost; but when I run npm build and upload the plugin to my production site, it tells me that there are some invalid file names and, even though the plugin shows up in the plugin page. The block does not appear in the page editor. Any ideas?

  • @jessicadesjardins1165
    @jessicadesjardins1165 Před 4 lety

    Does this also generate the posts in the editor when the block is in “preview” mode?

    • @mnaoh6704
      @mnaoh6704 Před 3 lety

      just try and click on Preview !

  • @raj080288
    @raj080288 Před 3 lety

    What's the difference creating the blocks in React.js and PHP (Wordpress)?

  • @tamidynes
    @tamidynes Před 4 lety

    Hi,
    Thank you so much!
    I am developing on localhost and it doesn't save the selectedCategory when I refresh, even though I did execltly your steps.
    Also, I used the create-block bundle instead of cgb, because I couldn't get the wp-env work with cgb for some reason. Everything went well until the setAttributes didn't save after refreshing.
    How can I make the selectedCategory saved?
    Thanks again,
    Tami

    • @WPCasts
      @WPCasts  Před 4 lety

      Hey Tami! This is tough without being able to see whole picture. What issue were you running into with cgb?

    • @tamidynes
      @tamidynes Před 4 lety

      @@WPCasts I am using wp-env, and it could not run the local Wordpress env from the plugin directory created by cgb, and it does work with create-block. Is this where the problem comes from? Using create-block instead of cgb? To be clear, the attributes are modified by setAttributes, but then when I refresh the page the attributes are cleared as if nothing was selected.
      I appreciate your response and I understand it is hard to do it remotely without seeing the whole picture. I will keep trying to make it work and I will update you if I find a solution :)

  • @Labyrinthman
    @Labyrinthman Před 3 lety

    On the frontend I get
    Notice: Undefined index: selectedCategory
    And my code is exactly like yours.

  • @floris3766
    @floris3766 Před 4 lety

    Why does this live inside a plugin and not inside a folder in a custom theme for example?

    • @WPCasts
      @WPCasts  Před 4 lety

      Housing your components in a plugin is typically the best practice to go because a plugin is more portable than some code inside of a theme. That said, if you don't plan on reusing those components, you can place them in the theme if you want.

  • @raj080288
    @raj080288 Před 3 lety

    is this known as an inner block?

  • @alexlytle089
    @alexlytle089 Před 3 lety

    How can you add multiple blocks to the same project?

    • @leonh5453
      @leonh5453 Před 3 lety

      Yes, will each block be a plugin with this create-guten-block boilerplate?

  • @michael.knight
    @michael.knight Před 5 lety

    Why did they have to make it so complex? The ACF way seems much more logical. But I guess there may be some downsides to that approach too.

  • @kensleylewis
    @kensleylewis Před 3 lety

    unfortunately I couldn't get through the first 6 minutes of this video, as I do not get the empty object or category lists posted in my browser console. either this coding is outdated or the block plugin code changed since the making of this video tutorial.

  • @Labyrinthman
    @Labyrinthman Před 4 lety

    @WPCasts
    I get Uncaught (in promise) {
    "code": "invalid_json",
    "message": "The response is not a valid JSON response."
    }
    and this is my code
    attributes:{
    categories:{
    type:'object'
    },
    selectedCategory:{
    type:'string'
    }
    },
    edit: function ( props ) {
    if( !props.attributes.categories){
    wp.apiFetch({
    url:'/wp-json/wp/v2/categories'
    }).then(categories =>{
    props.setAttributes({
    categories:categories
    })
    });
    }
    if( !props.attributes.categories){
    return 'Loading...';
    }
    if( props.attributes.categories && props.attributes.categories.length===0){
    return 'No categories found...please add some';
    }
    console.log( props.attributes);
    return (

    {
    props.attributes.categories.map(category =>{
    return(
    {category.name}
    )
    })
    }

    );
    },
    save: function () {
    return null;
    },
    } );

    • @ollip3452
      @ollip3452 Před 3 lety

      If you are doing this in local and you home address in local is like this "localhost/you-site/"

    • @Labyrinthman
      @Labyrinthman Před 3 lety

      @@ollip3452 You mean like this?
      wp.apiFetch({
      url:'localhost/you-site/wp-json/wp/v2/categories'
      })

  • @tagfat
    @tagfat Před 4 lety

    What is the difference between a tutorial and just doing something while talking. According to this "tutorial" there is no difference. So no overview, no content separation or sequencing. Just lacks the mouse wiggle and a some errors to be a total failure.

    • @WPCasts
      @WPCasts  Před 4 lety

      Sorry that you didn't like it. If you have some example tutorials that are good examples to follow, I'd love to see them! Thanks!

    • @tagfat
      @tagfat Před 4 lety

      @@WPCasts I kinda think that this kinda thing is a product of talking too much with people mostly like yourself. As in focusing your attention on people who can do 70 - 90 % of what you do. And are helped by an unprepared, lazy, relaxed style tutorial. Same stuff is aggravating if you actually need to get an understanding of the stuff covered. Made worse by a long language sausage that makes it impossible to chuck it down to something digestable. Is it really that hard to break it down to 3 or 7 parts with a bit of separation?

    • @tagfat
      @tagfat Před 4 lety

      " If you have some example tutorials that are good examples to follow, I'd love to see them!"
      I will try to find some. In the meantime Larry McEarneney has some wonderful methods on how to structure text to make it work for readers. I think he covers a lot that is useful for making tutorials in video form as well. I often find tutorials frustrating. That is in no way your problem. But I would suggest that making more accessible stuff will help you grow a much larger audience.
      czcams.com/video/vtIzMaLkCaM/video.html

    • @tagfat
      @tagfat Před 4 lety

      Good ole WP-Scuptor have made some really good tutorials. They are by now very dated and way below my present level of understanding. But he is a real pro with regards to structure, organisation, completeness. You can see that he knows exactly what he is doing and leaves nothing to chance. It is much simpler stuff, and off course it gets harder to do more advanced stuff with this kind of approach. But some approximation would do nicely too.
      czcams.com/video/DyARzdLKjKw/video.html
      I watched a Traversy Media tutorial on how to do a plugin today. I will definitely use that as a learning experience. It is a bit above my level, but I trust him to be clear, predictable, reliable and detailed enough that I want ragequit after 5 attempts, but actually get something to work and learn from it. Sadly he has some serious health issues and is not able to do as much as he has done.
      czcams.com/video/eZn3tfF5GFM/video.html

    • @leonh5453
      @leonh5453 Před 3 lety

      ​@@tagfat Why don't you go and make a better tutorial yourself?

  • @sandeepjainwp
    @sandeepjainwp Před rokem

    after entering postPerPage once unable to change again with code