...

/

Exploring Blocks

Exploring Blocks

Get introduced to different built-in blocks provided by WordPress.

Blocks enable us to use WordPress as a page builder tool. We can use the core WordPress blocks or create our own blocks and combine them in a certain way to create a page. Right now the template files of our excellence-block theme have hardcoded static code. In the classic Excellence theme, we used PHP to dynamically get much of the information on a page dynamically, like the title, content, banner area etc. In this lesson, we will see how to achieve the same in a block theme.

Navigate to the block editor from the admin dashboard by clicking on "Appearance" and then "Editor." Open the Single Post template that we created in the last lesson. Right now, the template has a paragraph with a test message.

Post title and content blocks

Let’s say we want to display the title of the blog post dynamically. WordPress has a block named "Post Title." We can use it to dynamically fetch the title of a post or page.

To add a new block in the template file, type a forward slash. It displays a list of all the available blocks. Type /post title and select the post title block.

Press + to interact
Adding a block
Adding a block

Similarly, WordPress also provides a "Post Content" block. As the name suggests, it dynamically pulls in the content of the post or page from the database. Below the Post Title block, add the Post Content block.

Press + to interact
Post title and content blocks
Post title and content blocks

Now save the template and from the dashboard, go to the Posts options and view a blog post on the frontend. We can see the title and content of the post from the database.

Query loop block

The query loop block runs a custom query to display a list of posts based on certain parameters. We can use this block to display recent blog posts on the front page.

Open the "Index" template from the "Editor" and ...