Custom taxonomy template shows different content if there are children

Đã có trọn bộ đề thi thử THPT Quốc Gia 2022 các môn: vip.dethihsg247.com

I am trying to create a template for my custom post type (products) custom taxonomy (product_category) that will show sub categories if there are any and but if there aren’t, then it should list the products.

As an example

categories:

category1
category2
-sub-category1
-sub-catetory2
category3

so if the url is loaded (/product_category/category1) then it will list the products in that category.

However if (/product_category/category2) is loaded, then it will show the names “subcategory1” and “subcategory2” but no actual products.

Here is what I came up with so far, but it feels “hacky” is there a better way to do this?

Xin chào các bạn và quý Thầy Cô. Hãy nhập từ khóa mình muốn vào ô tìm kiếm trên Website để tìm kiếm mọi thứ hoặc trên google các bạn hãy nhập từ khóa + dethihsg247.com để tìm kiếm các bài viết của chúng tôi nhé.
  • Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
  • Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
  • Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.

Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com