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

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.ย. 2024
  • 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/k...
    *Don't forget to subscribe!*
    *SOCIAL*
    Twitter: / alexanderbyoung
    Instagram: / the_alex_young
    #WordPress #Gutenberg #React

ความคิดเห็น • 72

  • @WPCasts
    @WPCasts  5 ปีที่แล้ว +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_

  • @andreranulfo-dev8607
    @andreranulfo-dev8607 9 หลายเดือนก่อน

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

  • @artabramov2254
    @artabramov2254 4 ปีที่แล้ว +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 5 ปีที่แล้ว

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

  • @devnebula
    @devnebula 4 ปีที่แล้ว +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 4 ปีที่แล้ว

      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?

  • @travholt
    @travholt 5 ปีที่แล้ว

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

    • @WPCasts
      @WPCasts  5 ปีที่แล้ว

      I'm glad you found it instructional! Cheers!

  • @antoineoriot5538
    @antoineoriot5538 2 ปีที่แล้ว

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

  • @nateandersson
    @nateandersson 3 ปีที่แล้ว

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

  • @JustinTiell
    @JustinTiell 3 ปีที่แล้ว

    This is exactly what I needed! Great video!

  • @andreranulfo-dev8607
    @andreranulfo-dev8607 9 หลายเดือนก่อน

    Just Priceless!

  • @miguelmachado6862
    @miguelmachado6862 5 ปีที่แล้ว +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  5 ปีที่แล้ว +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 5 ปีที่แล้ว

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

  •  3 ปีที่แล้ว

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

  • @rayremnant
    @rayremnant 5 ปีที่แล้ว +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

  • @escuelawordpress1308
    @escuelawordpress1308 5 ปีที่แล้ว

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

  • @oliviaposch187
    @oliviaposch187 3 ปีที่แล้ว

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

  • @sandeepjainwp
    @sandeepjainwp ปีที่แล้ว

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

  • @nitdesign
    @nitdesign 4 ปีที่แล้ว +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!

  • @pahtashow
    @pahtashow 4 ปีที่แล้ว

    A full course on wordpress development please!

  • @qoraicheyassine6452
    @qoraicheyassine6452 3 ปีที่แล้ว

    Thanks for this

  • @zipponvr7043
    @zipponvr7043 3 ปีที่แล้ว

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

  • @diederickb1806
    @diederickb1806 3 ปีที่แล้ว +1

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

  • @danihazler
    @danihazler 4 ปีที่แล้ว

    This tutorial is so helpful! Thanks a lot!

  • @user-en8fd9ut5q
    @user-en8fd9ut5q 3 ปีที่แล้ว

    Great lesson. Good luck!

  • @dimor22
    @dimor22 4 ปีที่แล้ว

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

  • @LeandroBergSchulz
    @LeandroBergSchulz 4 ปีที่แล้ว +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?

  • @lloydmangin2335
    @lloydmangin2335 ปีที่แล้ว

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

  • @Labyrinthman
    @Labyrinthman 3 ปีที่แล้ว

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

  • @errorerror1337
    @errorerror1337 5 ปีที่แล้ว

    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  5 ปีที่แล้ว

      You can and should! Thanks for the feedback :)

  • @rovshen.public
    @rovshen.public 5 ปีที่แล้ว

    Thank you so much! For this video!

  • @antonfsd
    @antonfsd 4 ปีที่แล้ว +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 4 ปีที่แล้ว +1

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

  • @jannemanhuman4237
    @jannemanhuman4237 2 ปีที่แล้ว

    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 2 ปีที่แล้ว +1

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

  • @mostafamrabet7883
    @mostafamrabet7883 4 ปีที่แล้ว

    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.

  • @raj080288
    @raj080288 3 ปีที่แล้ว

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

  • @oguz-kagan
    @oguz-kagan 4 ปีที่แล้ว

    thank you really helpful

  • @renanbessa8778
    @renanbessa8778 3 ปีที่แล้ว

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

  • @carlosg8716
    @carlosg8716 5 ปีที่แล้ว

    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?

  • @MorganHvidt
    @MorganHvidt 5 ปีที่แล้ว

    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  5 ปีที่แล้ว +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 5 ปีที่แล้ว

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

  • @alexlytle089
    @alexlytle089 3 ปีที่แล้ว

    How can you add multiple blocks to the same project?

    • @leonh5453
      @leonh5453 3 ปีที่แล้ว

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

  • @tamidynes
    @tamidynes 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

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

    • @tamidynes
      @tamidynes 4 ปีที่แล้ว

      @@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 :)

  • @MatthewMcDonald
    @MatthewMcDonald 3 ปีที่แล้ว

    Super!

  • @kensleylewis
    @kensleylewis 3 ปีที่แล้ว

    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.

  • @floris3766
    @floris3766 4 ปีที่แล้ว

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

    • @WPCasts
      @WPCasts  4 ปีที่แล้ว

      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.

  • @jessicadesjardins1165
    @jessicadesjardins1165 4 ปีที่แล้ว

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

    • @mnaoh6704
      @mnaoh6704 4 ปีที่แล้ว

      just try and click on Preview !

  • @raj080288
    @raj080288 3 ปีที่แล้ว

    is this known as an inner block?

  • @michael.knight
    @michael.knight 5 ปีที่แล้ว

    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.

  • @Labyrinthman
    @Labyrinthman 4 ปีที่แล้ว

    @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 3 ปีที่แล้ว

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

    • @Labyrinthman
      @Labyrinthman 3 ปีที่แล้ว

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

  • @tagfat
    @tagfat 4 ปีที่แล้ว

    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  4 ปีที่แล้ว

      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 4 ปีที่แล้ว

      @@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 4 ปีที่แล้ว

      " 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.
      th-cam.com/video/vtIzMaLkCaM/w-d-xo.html

    • @tagfat
      @tagfat 4 ปีที่แล้ว

      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.
      th-cam.com/video/DyARzdLKjKw/w-d-xo.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.
      th-cam.com/video/eZn3tfF5GFM/w-d-xo.html

    • @leonh5453
      @leonh5453 3 ปีที่แล้ว

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

  • @sandeepjainwp
    @sandeepjainwp ปีที่แล้ว

    after entering postPerPage once unable to change again with code