Display the Latest Products Section - P4 - Using Meta Box + Zion
Tags: tutorial, metabox, zion, restaurant
Published: 2022-08-23 03:58:47

In the previous posts in <a href="https://metabox.io/series/latest-products/">this series</a>, we’ve gone through several methods to <strong>display the latest products in a section on the homepage</strong> using Meta Box and some page builders. In today's practice, we're going to figure out another way to do it <strong>using Meta Box and Zion Builder</strong>.

<!--more-->

This is my example.

<img class="aligncenter" src="https://i.imgur.com/OnUhpH9.png" alt="example for displaying the latest products in a section on the homepage using Meta Box and Zion" width="1000" height="618" />
<h2>Video Version</h2>
https://youtu.be/wgklwMfolEc
<h2>Before Getting Started</h2>
In this case, my products are restaurants. Each one’s information will be saved in a post of a custom post type. The extra information such as address, logo, voucher will be saved in custom fields.

So to get started, we need the <a href="https://wordpress.org/plugins/meta-box/">Meta Box core plugin</a> to have the framework for creating custom post type and custom fields. It’s free, so you can download it directly from <a href="https://wordpress.org/plugins/meta-box/">wordpress.org</a>.

For the advanced features from Meta Box, we need some of its extensions:
<ul>
 	<li><a href="https://metabox.io/plugins/custom-post-type/">MB Custom Post Types &amp; Custom Taxonomies</a>: to create custom post types;</li>
 	<li><a href="https://metabox.io/plugins/meta-box-builder/">Meta Box Builder</a>: to have an intuitive UI to create custom fields in the backend;</li>
</ul>
They’re all in the <strong>Meta Box AIO</strong>. If you haven’t had it, you can download and install each extension individually.

Finally, make sure you have <strong>Zion Builder Pro</strong> on your site.
<h2>Step 1: Create a Custom Post Type</h2>
Go to <strong>Meta Box &gt; Post Types &gt; Add New</strong> to create a new post type.

<img class="aligncenter" src="https://i.imgur.com/UGv6Sma.png" alt="create a new custom post type" width="1000" height="540" />

After publishing, we’ll have a new menu named <strong>Restaurants</strong> in the admin dashboard.

<img class="aligncenter" src="https://i.imgur.com/tsUMKuy.png" alt="a new menu display on the left sidebar" width="1000" height="487" />

Then, let’s create custom fields in the next step.
<h2>Step 2: Create Custom Fields</h2>
Go to <strong>Meta Box &gt; Custom Fields</strong> to create fields. I’ll create all the fields with the structure like this:

<img class="aligncenter" src="https://i.imgur.com/8QB87vl.png" alt="the custom fields that we'll create for the post type" width="1000" height="510" />There are no special settings for them.

After creating all the fields, move to the Settings tab. Remember to choose the <strong>Location</strong> as <strong>Post type</strong> and select your product’s post type to apply these fields to it.

<img class="aligncenter" src="https://i.imgur.com/u6j1aPR.png" alt="set location for the fields to apply them to the wanted post type" width="1000" height="512" />

Now, when creating a new post in my <strong>Restaurant</strong> post type, the custom fields will be here.

<img class="aligncenter" src="https://i.imgur.com/vgVr0Cm.png" alt="the custom fields displayed in the post editor" width="1000" height="556" />

Let’s move to the next step to create a section for the latest restaurants on the homepage.
<h2>Step 3: Add a Section for the Latest Products on Homepage</h2>
Go to <strong>Pages &gt; Homepage</strong> and click <strong>Edit with Zion Builder</strong>.

<img class="aligncenter" src="https://i.imgur.com/QBJdACX.png" alt="edit the homepage with Zion builder" width="1000" height="540" />

First, add a <strong>Section</strong> element to the page. Then, add a <strong>Heading</strong> for it.

<img src="https://i.imgur.com/YKyOBSB.png" alt="add a section element in the homepage" width="1000" height="466" /> Add a <strong>Section</strong> element in the homepage

<img src="https://i.imgur.com/cm51Klz.png" alt="add a heading for the section" width="1000" height="466" /> Add a heading for the section

Next, add a <strong>Container</strong> and a <strong>Column</strong> element inside it.

<img src="https://i.imgur.com/nXcXLOt.png" alt="add a container inside the section" width="1000" height="466" /> Add a container inside the section

<img src="https://i.imgur.com/mPNhMHQ.png" alt="Add a Column element" width="1000" height="466" /> Add a Column element

In the settings of the <strong>Column</strong> element, go to the <strong>Advanced tab &gt; Repeater Options</strong> and <strong>enable the repeater provider</strong>.

<img class="aligncenter" src="https://i.imgur.com/GHIcLD6.png" alt="enable the repeater provider for the column" width="1000" height="523" />

Choose the <strong>Query type</strong> as <strong>Query builder</strong> and select the <strong>Post type</strong> as the post type you want. In my case, it is Restaurant.

<img class="aligncenter" src="https://i.imgur.com/XQ0dPUI.png" alt="query the posts from the wanted post type" width="1000" height="518" />

Since we’re going to display the latest posts first then the oldest ones, set order posts by <strong>date</strong> and then choose the <strong>Descending</strong> option.

<img class="aligncenter" src="https://i.imgur.com/AVlGARR.png" alt="set order for the posts" width="1000" height="594" />

To display all the posts in the chosen post type, remember to <strong>enable the repeater consumer</strong>.

<img class="aligncenter" src="https://i.imgur.com/DShULdO.png" alt="enable the repeater consumer" width="1000" height="501" />

Because we haven’t chosen any kind of information of the product to show yet, it’s still blank there.

Now, add some elements to display the information such as restaurants’ name, featured image, address, voucher and logo.

To display the featured images of the post, add an <strong>Image </strong>element. Then, connect it to the featured image of the post by using the <strong>Use dynamic data</strong> button. In the list of displaying options, find the <strong>Featured image</strong> in the <strong>Post</strong> section.

<img class="aligncenter" src="https://i.imgur.com/KPJJLgR.png" alt="Use dynamic data button to get data from posts" width="1000" height="637" />

Now, all the featured images of the restaurants are shown.

<img class="aligncenter" src="https://i.imgur.com/dUZJ90J.png" alt="the data from posts are obtained" width="1000" height="638" />

Do likewise for the name of the restaurant, means the post title. Choose a <strong>Heading</strong> element &gt; <strong>Use dynamic data &gt; Post Title</strong>.

<img class="aligncenter" src="https://i.imgur.com/jkFfzLD.png" alt="get post titles for the name of restaurants" width="1000" height="512" />

For the address, choose the <strong>Text</strong> element. Then, also click the <strong>Use dynamic data</strong> button. Since the address is saved in a custom field created by Meta Box, find <strong>Meta Box Field</strong> in the list of options.

<img class="aligncenter" src="https://i.imgur.com/qZAGjOd.png" alt="Use dynamic data to get data from the custom fields created by Meta Box" width="1000" height="512" />

Then, choose the corresponding field.

<img class="aligncenter" src="https://i.imgur.com/StncaRP.png" alt="choose the wanted fields to get the corresponding data" width="1000" height="542" />

Now, the addresses corresponding to each restaurant will be shown.

<img class="aligncenter" src="https://i.imgur.com/VQ19mPp.png" alt="the addresses corresponding to each restaurant will be shown" width="1000" height="507" />

For other information such as voucher and logo, do likewise.

<img src="https://i.imgur.com/SKqhCc3.png" alt="Add a Text element and link it to the Voucher field" width="1000" height="504" /> Add a <strong>Text</strong> element and link it to the Voucher field[/caption]

<img src="https://i.imgur.com/kuhLDuH.png" alt="Add a Image element and link it to the Logo field" width="1000" height="479" /> Add an <strong>Image</strong> element and link it to the Logo field

Now, all the information of the restaurant has been obtained and displayed in a section on the homepage.

<img class="aligncenter" src="https://i.imgur.com/VThxpkm.png" alt="all the information of the restaurant has been obtained and displayed in a section on the homepage" width="1000" height="459" />
<h2>Step 4: Style the Section</h2>
You can easily style the layout of the section as you want in Zion visual builder.

<img class="aligncenter" src="https://i.imgur.com/eOM2VD4.png" alt="style the layout of the section as you want in Zion visual builder" width="1000" height="486" />

For advanced styling, you may need some CSS code. For example, I use <a href="https://github.com/wpmetabox/tutorials/blob/fbab355fd907a7c90a31f805e8fdf285e5e20b45/display-latest-posts-with-Zion/custom.css">this one</a>.

<img class="aligncenter" src="https://i.imgur.com/OFF1lNj.png" alt="use CSS for advanced styling" width="1000" height="491" />

Then the section will have a new look as below:

<img class="aligncenter" src="https://i.imgur.com/OnUhpH9.png" alt="the section got a new look" width="1000" height="618" />
<h2>Last Words</h2>
We’ve gone through all the steps to display the latest products section using Meta Box plugin and Zion Builder. Try it out and share the results in the comment section.

In the event that you have projects using another page builder, refer to the other posts in <a href="https://metabox.io/series/latest-products/">this series</a>. Or, if you want to suggest any tutorials, feel free to leave a comment. Thank you for reading. Good luck!