Are you looking for a way to have thumbnails for custom taxonomies as well as featured images for them? Having taxonomy thumbnails will be a good way to make that page be more attractive. Let’s dive in to explore how to display them with MB Views from Meta Box.

This is an example for the portfolio page that we will create in this practice.

An example for the portfolio page

We often use images in a portfolio page as a term of a taxonomy, which is about an accommodation type, with its own thumbnail.

The image used for the thumbnail also will be used to be the featured image of the archive page of the taxonomy’s term.

This is the featured image of the archive page

Video Version

Before Getting Started

In this practice, we need the Meta Box core plugin to create custom post types, taxonomies as well as a custom field to store the images for the taxonomy. You can download it directly from wordpress.org.

We also need some advanced features from Meta Box which is from some of its extensions:

  • MB Custom Post Type: to create a custom post type and custom taxonomy for the portfolio;
  • MB Term Meta: to add custom field created with Meta Box to categories, tags, or any custom taxonomies;
  • MB Views: to create templates to display the thumbnails and the featured images without touching the theme’s files;
  • Meta Box Builder: to have an intuitive UI to create the custom field for the images.

You can install them individually or just use Meta Box AIO.

Create a New Custom Post Type

Go to Meta Box > Post Types > Add New.

Go to Meta Box to create a new custom post type.

After publishing, you will see a new menu displayed in the admin dashboard.

A new menu of the post type displayed in the admin dashboard.

Create a Custom Taxonomy

Go to Meta Box > Taxonomies > Add New to create a new taxonomy.

Go to Meta Box to create a new custom taxonomy for the created post type.

When creating the wanted taxonomy, move to the Post Types tab, and choose Portfolio to apply this taxonomy to the post type as you want.

Apply the creating taxonomy to a post type.

Now, you can go back to the created post type, and see a new submenu.

There will be a place to add new term to the custom taxnonomy.

Let’s add some terms for the taxonomy. These are some terms that I created for illustration.

These are some example terms that created for illustration

However, there is no place for any kind of images for custom taxonomy so far. Let’s go ahead to create one with the help of custom fields from Meta Box.

Create Custom Fields

In this practice, I’ll create two custom fields for the taxonomy to give you a more comprehensive guide. In your real case, I recommend you choose one of them and use only one field for simplicity.

Go to Meta Box > Custom Fields to create the fields.

Go to Meta Box > Custom Fields to create the fields.

First, I choose the field in the type as URL. This one allows you to save links of the images. It’ll be useful when you save images in a 3rd party service instead of uploading on your site.

Next, choose Single Image for the one uploading the images. This one allows you to upload an image and save it to your website gallery.

I'm creating two fields in two common types.

After having the field, move to the Settings tab, choose Location as Taxonomy, and select Portfolio Type which is the created taxonomy. Notice that you can set the location as the taxonomy only when you enable the MB Term Meta extension.

Assign the custom field to the Portfolio Type that is the created taxonomy.

Go back to create a new term for the taxonomy and you will see the created custom fields.

The created custom field display when creating a new term for the taxonomy of the portfolio.

Now, you also can edit some terms and see the fields to have an image for each term.

You also can edit some terms and see the fields to have an image for each term.

Display Images as Taxonomy’s Thumbnails

Create the Page and Template

Go to Pages to create a new page for the portfolio. I will add content for this page via a template created with MB Views.

Go to Pages to create a new page for the portfolio.

Go to Meta Box > Views to create a template.

Go to Views to create a new template for the portfolio page.

Get Terms and Images

In the template tab of the view, we’ll add some lines of code.

{% set args = {taxonomy: 'portfolio-type',hide_empty: false} %}
{% set portfolios = mb.get_terms( args ) %}
{% for portfolio in portfolios %}
    {% set image_upload = mb.get_term_meta( portfolio.term_id, 'upload_portfolio_thumbnail', true ) %}
    {% set image_url = mb.get_term_meta( portfolio.term_id, 'url_portfolio_thumbnail', true ) %}
{% endfor %}

Add some lines of code to get terms and images.

In there:

{% set args = {taxonomy: 'portfolio-type',hide_empty: false} %}

This line is to declare that we’ll get data from the taxonomy because the images are saved in a custom field that is assigned to a taxonomy. 'portfolio-type' is the slug of the taxonomy.

Next, we use the mb.get_terms() function to get terms from the taxonomy.

{% for portfolio in portfolios %}
 
{% endfor %}

I have this loop to display all the terms that we got from the taxonomy.

Create some variables to get images from custom fields.

{% set image_upload = mb.get_term_meta( portfolio.term_id, 'upload_portfolio_thumbnail', true ) %}
{% set image_url = mb.get_term_meta( portfolio.term_id, 'url_portfolio_thumbnail', true ) %}

In this part, the mb.get_term_meta () function helps to obtain data from the custom fields. 'upload_portfolio_thumbnail' is the ID of the single image field for uploading, and 'url_portfolio_thumbnail' is the ID of the URL field.

Add Condition to Display Images

We have two fields for storing images while only one image can be displayed, so I have a condition in the next lines to choose which one will be displayed.

{% if image_upload %}
    {% set image_upload_link = mb.wp_get_attachment_image_src( image_upload, large) %}
    <img src="{{ image_upload_link[0] }}">
{% elseif image_url %}
    <img src="{{ image_url }}">
{% else %}
    <img src="https://metabox.io/wp-content/uploads/2020/03/MB-Views-extension.jpg">
{% endif %}

This one will be added inside the loop.

Having a condition to choose image from which field will be displayed.

In there:

{% if image_upload %} is to know if this image_upload variable carries any value or not, which also means the single image field stores any image or not. If yes, the next line will run:

{% set image_upload_link = mb.wp_get_attachment_image_src( image_upload, large) %}

It’s to get the url of the uploaded image from the image_upload variable. And then, we’ll use the link to print the url to display the image on the page using this: <img src="{{ image_upload_link[0] }}">.

{% elseif image_url %} means that if there is no image in the uploading field (the image_upload variable is empty), we will examine this image_url variable. Also, print the image from the stored url using this: <img src="{{ image_url }}">.

In the case that the image_url variable is empty as well, you should set a default image for the thumbnail. Just use the URL of any image to set as default in this line:

<img src="https://metabox.io/wp-content/uploads/2020/03/MB-Views-extension.jpg">

Set a default image for the thumbnail if there is no image store in the custom fields.

That’s all for the thumbnails.

Notice

In your real case, you may have only one field for the images, so you can remove one of these lines depending on which field you don’t want to use. As well as, remove the condition and corresponding part of displaying the images.

Remember to remove corresponding lines of code when you have only field for images.

Remember to change the name of the variables as you want.

Display Terms Information

{{ portfolio.name }}
{{ portfolio.description }}

Two lines above are the title and the description of the term. You can type for it, or insert them from this Insert Field button.

You can choose to type the code or insert field directly on the template.

We’ve done getting all the needed information for the portfolio.

Go down to the Settings section of the view, set the Type setting as Singular. Then, set a rule for Location to apply the template to the portfolio page.

Set the location for the template to apply it to the portfolio page.

Go to the page on the front end, you'll see the data displayed.

The images and the terms information display on the page.

Style the Page

To style the page, go back to the edit template in the Views.

Before styling, we should add some div tags and classes to divide information into different parts.

Add div tags and classes to the template for styling.

This line is to create a button to go to the term’s archive page.

Add a button for each terms to link to the archive page.

This is the page on frontend now.

The page after divided into section using div tags.

Back to the view again, go to the CSS tab, add some code to style the page.

Add CSS to the template.

Now you will see the Portfolio page displayed with a better look.

The portfolio page after styling.

Display Images as Featured Images

I have a pre-made template for this archive page. But, there is no featured image on the page as default. So I will take the image saved in the custom field to be the featured image of this page, and display it on the top.

The archive page as default.

Go back to Meta Box to create a new view.

Go to view to create a new template for the featured image.

And add this script:

{% if term.taxonomy == 'portfolio-type' %}
    {% set image_upload = term.upload_portfolio_thumbnail.full.url %}
    {% set image_url = term.url_portfolio_thumbnail %}
    {% if image_upload %}
            <img src="{{ image_upload }}">
        {% elseif image_url %} 
            <img src="{{ image_url }}">
        {% else %}
            <img src="https://metabox.io/wp-content/uploads/2020/03/MB-Views-extension.jpg">
        {% endif %}
{% endif %}

Add some code to the template.

I also divide the code into parts to explain it clearer.

Define the Archive Page

{% if term.taxonomy == 'portfolio-type' %}

Since we will display the image on the archive page of the term, I have this condition to check whether the current page is the expected page or not. 'portfolio-type'  is the ID of the taxonomy.

Get Images

We will use the same structure of code in the previous template for the portfolio page to get URLs of the images.

{% set image_upload = term.upload_portfolio_thumbnail.full.url %}
{% set image_url = term.url_portfolio_thumbnail %}

Create variables to get images from custom fields.

These upload_portfolio_thumbnail and url_portfolio_thumbnail variables are the fields' IDs.

These variables are the fields' IDs

That’s all to get images.

Condition to Display the Images

The next part is the condition. It has the same logic as the one we use for the portfolio page, so I will not dig in any more.

Add a condition to choose image from which field will be displayed.

Apply to the Page

Now, I’ll leave this setting as default to generate this template as a shortcode.

Set the template as a shortcode.

Copy the shortcode. Then, you can input this shortcode to any place on the page template.

Add the shortcode to any place on the page.

The page of a term has the image now.

The image displayed on the page.

If you want to have beyonce styling for the image, go back to the template of this featured image and add some CSS.

Add CSS to the template of displaying image to style it.

This is the new look of the featured image of the page.

The page with the featured image after styling.

Last Words

Hopefully, this tutorial will give you a hand in creating taxonomy thumbnails & featured images by using MB Views with Meta Box.

If you use other page builders, you can dig into the series on how to create taxonomy thumbnails & featured images with different page builders.

Or, if you are looking for adding thumbnails and featured images for category, this post is for you.

If you want to suggest any tutorials, feel free to leave a comment and keep track of our blog. Thanks for reading!

Other case studies you might be interested in

  1. Create A Dynamic Landing Page in WordPress Using Custom Field
  2. Create a Filter to Find Hotels by Location
  3. Create an OTA Website Like Booking.com with Meta Box Plugin - P1: Create a Page to Introduce Hotel Rooms
  4. Create an OTA Website Like Booking.com with Meta Box Plugin - P2: Create Filters on the Archive Page
  5. Create an OTA Website Like Booking.com with Meta Box Plugin - P3: Create Filters for Single Hotel Pages
  6. Create Dynamic Favicon in WordPress using Meta Box plugin
  7. Create Posts Series in WordPress Using Meta Box
  8. Display The Latest Products Section - P2 - Using Meta Box and Elementor
  9. Display The Latest Products Section - P3 - Using Meta Box And Oxygen
  10. How to Add Custom Fields for WooCommerce - P2 - Using MB Views
  11. How to Add Custom Fields to Display Banners using Meta Box Plugin
  12. How to Add Guest Authors and Guest Posts - Using Meta Box
  13. How to Add Related Posts - Using Custom Fields
  14. How to Build a Hotel Booking Website Using Meta Box - P1
  15. How to Build a Hotel Booking Website Using Meta Box - P2 - Booking Page in Backend
  16. How to Build a Hotel Booking Website Using Meta Box - P4 - Booking Management Page
  17. How to Build a Hotel Booking Website Using Meta Box – P3 – Booking Page for Customer
  18. How to Create a Classified Ads Website using Meta Box
  19. How to Create a Custom 404 Page in WordPress - P1 - Using Meta Box and Elementor
  20. How to create a FAQs page - P5 - Using Meta Box and Breakdance
  21. How to Create a Product Page - P2 - Using Meta Box and Oxygen
  22. How to Create a Product Page - P3 - Using Meta Box and Bricks
  23. How to Create a Product Page - P4 - Using Meta Box and Elementor
  24. How to Create a Product Page - P5 - Using Meta Box and Gutenberg
  25. How to Create a Product Page - P6 -Using Meta Box and Breakdance
  26. How to Create a Product Page - P7 - Using Meta Box + Kadence
  27. How to Create a Product Page - P8 - Using Meta Box and Brizy
  28. How to Create a Product Page - P9 - Using Meta Box and Divi
  29. How to Create a Product Page using Meta Box Plugin
  30. How to Create a Recipe - P2 - Using Meta Box and Oxygen
  31. How to Create a Recipe - P3 - Using Meta Box and Elementor
  32. How to Create a Recipe - P4 - Using Meta Box and Bricks
  33. How to Create a Recipe - P5 - Using Meta Box and Zion
  34. How to Create a Recipe - P6 - Using Meta Box and Brizy
  35. How to Create a Recipe - P7 - Using Meta Box and Breakdance
  36. How to Create a Recipe - P8 - Using Meta Box and Kadence
  37. How to Create a Recipe - P9 - Using Meta Box and Divi
  38. How to Create a Recipe with Meta Box Plugin
  39. How to Create a Simple Listing - P2 - Using Meta Box and Bricks
  40. How to Create a Simple Listing - P3 - Using Meta Box and Breakdance
  41. How to Create a Simple Listing - P4 - Using Meta Box and Elementor
  42. How to Create a Team Members Page - P1- Using Meta Box and Elementor
  43. How to Create a Team Members Page - P2 - Using Meta Box and Oxygen
  44. How to Create a Team Members Page - P3 - Using Meta Box and Bricks
  45. How to Create a Team Members Page - P4 - Just Meta Box
  46. How to Create a Team Members Page - P6 - using Meta Box and Breakdance
  47. How to Create a Team Members Page - P7 - Using Meta Box and Kadence
  48. How to Create a Video Gallery Page - P2 - Using Meta Box + Bricks
  49. How to Create a Video Gallery Page - P3 - Using Meta Box and Breakdance
  50. How to Create a Video Gallery Page - P4 - Using Meta Box + Elementor
  51. How to Create a Video Gallery Page - P5 - Using MB Views
  52. How to Create a Video Gallery Page - P6 - Using Meta Box and Zion
  53. How to Create a Video Gallery Page Using Meta Box + Oxygen
  54. How to Create ACF Flexible Content Field with Meta Box
  55. How to Create an Auto-Updated Cheat Sheet in WordPress
  56. How to Create an FAQs Page - P1 - Using Meta Box and Elementor
  57. How to create an FAQs page - P2 - Using Meta Box and Oxygen
  58. How to create an FAQs page - P4 - Using Meta Box and Bricks
  59. How to Create an FAQs Page - P6 - Using MB Views
  60. How to Create an FAQs Page - P7 - Using Meta Box and Divi
  61. How to Create an FAQs Page - P8 - Using Meta Box and Kadence
  62. How to Create an FAQs Page - P9 - Using MB Blocks
  63. How to Create an FAQs Page -P3- Using Meta Box
  64. How to Create Buttons with Dynamic Link using Custom Fields
  65. How to Create Category Thumbnails & Featured Images Using Custom Fields
  66. How to Create Download and Preview Buttons - P1 - Using Meta Box and Bricks
  67. How to Create Download and Preview Buttons - P2 - Using Meta Box and Oxygen
  68. How to Create Download and Preview Buttons - P3 - Using MB Views
  69. How to Create Download Buttons in WordPress - Using Custom Fields
  70. How to Create Dynamic Landing Page in WordPress - P1 - Using Meta Box and Elementor
  71. How to Create Dynamic Landing Page in WordPress - P2 - Using Meta Box and Bricks
  72. How to Create Menus for Restaurants - P1 - Using Meta Box and Elementor
  73. How to Create Menus for Restaurants - P2- Using Meta Box and Bricks
  74. How to Create Notification Using Custom HTML Field
  75. How to Create Online Admission Form for School or University
  76. How to Create Online Reservation Form for Restaurants using Meta Box
  77. How to Create Relationships - P1 - Using Meta Box and Oxygen
  78. How to Create Relationships - P2 - Using Meta Box and Bricks
  79. How to Create Relationships - P3 - Using MB Views
  80. How to Create Relationships - P4 - Using Meta Box and Breakdance
  81. How to Create Taxonomy Thumbnails & Featured Images - P2 - Using Meta Box and Oxygen
  82. How to Create Taxonomy Thumbnails & Featured Images - P3 - Using Meta Box and Bricks
  83. How to Create Taxonomy Thumbnails & Featured Images - P4 - Using MB Views
  84. How to Create YouTube Video Timestamps on WordPress Website - P1 - Using MB Views
  85. How to Display a Video Playlist - P1- Using MB Views
  86. How To Display All Listings On A Map With Meta Box
  87. How to Display Author Bio in WordPress - P1 - Using Meta Box and Bricks
  88. How to Display Author Bio in WordPress - P2 - Using MB Views
  89. How to Display Dynamic Banners in WordPress - P3 - Using MB Views
  90. How to Display Images from Cloneable Fields - P1 - with Gutenberg
  91. How to Display Images from Cloneable Fields - P2 - Using Meta Box and Oxygen
  92. How to Display Images from Cloneable Fields - P3 - with Elementor
  93. How to Display Images from Cloneable Fields - P4 - with Bricks
  94. How to Display Opening Hours for Restaurants - P1 - Using Meta Box + Gutenberg
  95. How to Display Opening Hours for Restaurants - P2 - Using Meta Box and Oxygen
  96. How to Display Product Variations - P1 - Using Meta Box and Gutenberg
  97. How to Display Product Variations - P2 - Using Meta Box and Oxygen
  98. How to Display Product Variations - P3 - Using Meta Box and Bricks
  99. How to Display the Dynamic Banners - P2 - Using Meta Box and Bricks

Leave a Reply

Your email address will not be published. Required fields are marked *