最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Split taxonomies on different pages

programmeradmin4浏览0评论

I'm working on a Woocommerce website and created a new taxonomy activity. I've added that taxonomy to the post type Product.

So a Product can have one of the following activity:

  1. Museum
  2. Food & Drinks
  3. Attractions
  4. Guided tours

To show all the Products, I've created taxonomy-activity.php which already shows all the products that have an activity taxonomy.

But I have to have all the Products with taxonomy Guided tours on a seperate page. And all the others on the other page. So there will be 2 pages: One page will be called Guided tours which only shows the guided tours and the other is called Activities.

Is it correct to do this with the taxonomy-{slug}.php or should I create a new page. For example: page-guidedtours.php which loops through all the Product with Guided tours taxonomy. And the other page page-activities.php which loops through all the Products without Guided tours taxonomy.

Sidenote: I'm using the plugin FacetWP in order to show the Product and created filters. So the query is created with the plugin and then the list of products in shown with a shortcode.

My current query is:

<?php
return [
   "post_type" => [
   "product"
],
   "post_status" => [
   "publish"
],
   "posts_per_page" => "18",
   "orderby" => "title",
   "order" => "ASC",
];

I'm thinking about created 2 Facets. One facet that shows the Guided tours. So in this case I have to add the term Guided tours to the query. And then other facet without the term Guided tours.

I'm working on a Woocommerce website and created a new taxonomy activity. I've added that taxonomy to the post type Product.

So a Product can have one of the following activity:

  1. Museum
  2. Food & Drinks
  3. Attractions
  4. Guided tours

To show all the Products, I've created taxonomy-activity.php which already shows all the products that have an activity taxonomy.

But I have to have all the Products with taxonomy Guided tours on a seperate page. And all the others on the other page. So there will be 2 pages: One page will be called Guided tours which only shows the guided tours and the other is called Activities.

Is it correct to do this with the taxonomy-{slug}.php or should I create a new page. For example: page-guidedtours.php which loops through all the Product with Guided tours taxonomy. And the other page page-activities.php which loops through all the Products without Guided tours taxonomy.

Sidenote: I'm using the plugin FacetWP in order to show the Product and created filters. So the query is created with the plugin and then the list of products in shown with a shortcode.

My current query is:

<?php
return [
   "post_type" => [
   "product"
],
   "post_status" => [
   "publish"
],
   "posts_per_page" => "18",
   "orderby" => "title",
   "order" => "ASC",
];

I'm thinking about created 2 Facets. One facet that shows the Guided tours. So in this case I have to add the term Guided tours to the query. And then other facet without the term Guided tours.

Share Improve this question asked Jul 10, 2020 at 6:43 DennisDennis 1358 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To show all the Products, I've created taxonomy-activity.php which already shows all the products that have an activity taxonomy.

That's not what taxonomy-activity.php is for. That template is the template that is used for displaying posts for each activity taxonomy term. So if you view Museum activity, that template will be used to display all Museum products, or if you view the Food & Drink activity the same template will be use to view Food & Drink products.

The template itself should not be choosing which posts to display. WordPress has already done that. All this template should be used for is presenting those posts. To loop through the products that WordPress has already query, you need to just use The Loop, not a custom query:

<?php 
if ( have_posts() ) : 
    while ( have_posts() ) : the_post(); 
        // Display product content
    endwhile; 
endif; 
?>

So WordPress will automatically make an archive available for each activity taxonomy which displays products that belong to it. You should not need to create a page or template for each one.

The same applies to post types. When you register a post type, like Products, it WordPress will automatically make an archive of all Products available if has_archive is set to true or a slug. To create a unique template for this archive, you need to create archive-product.php. This will then automatically be used at https://example/products/, where products is the post type name, or the slug pass to has_archive.

So what you need is archive-product.php which will be used when viewing all products at something like https://example/products/, and taxonomy-activity.php which will be used when viewing each activity links like https://example/activity/museum/ or https://example/activity/attractions/, as examples.

When is comes to adding FacetWP support for filtering these archives, you will need to consult their documentation, since 3rd-party plugins are off topic here, but when it comes to the required built in WordPress templates you need them set up like I described as a starting point.

发布评论

评论列表(0)

  1. 暂无评论