【发布时间】:2017-07-07 10:37:22
【问题描述】:
我有一个名为 products 的自定义帖子类型,它的分类名为 category
register_post_type( 'products',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' ),
'add_new_item' => __( 'Add New Product' ),
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'Products'),
'taxonomies' => array( 'category' )
)
);
我还有一个是brands
register_post_type( 'brands',
// CPT Options
array(
'labels' => array(
'name' => __( 'Brands' ),
'singular_name' => __( 'BRAND' ),
'add_new_item' => __( 'Add New Brand' ),
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'BRANDS'),
'taxonomies' => array( 'category' ),
)
);
我有一个名为 page-brands.php 的页面,我使用以下代码获取所有品牌。
$args = array(
'post_type' => 'brands',
'posts_per_page' => -1,
'order' => 'ASC'
);
$brands = new WP_Query( $args );
然后我显示品牌名称和徽标..
<a class="hvr-grow" href="<?php the_permalink(); ?>">
<img src="<?php the_field('brand_logo'); ?>">
<div class="brands_title"><?php the_title(); ?></div>
</a>
点击链接的品牌名称后,效果很好。它转到single-brands.php 页面。例如,我们点击了品牌名称“LG”。它将进入单一品牌页面,并显示其第一类的所有产品。
我得到了它的第一个类别,并通过另一个函数将其保存在 first_brand_category 中,然后在下面的查询中使用来显示。
$proucts_args = array(
'posts_per_page' => 50,
'post_type' => 'products',
'cat' => $first_brand_category,
);
$products_query = new WP_Query($proucts_args);
一切正常,直到完美。但现在我想更改上面的查询,因为我想为每个类别显示一个特定的产品。比如……
品牌是LG
LG 品牌的类别为 TV、Mobiles、Air Conditioners 等
电视类别有多种产品,手机等有多种产品。
我想通过该类别的超链接显示一种针对 LG 的特定电视产品、针对 LG 的一种特定手机产品和针对 LG 的一种特定空调产品。
我该怎么做?任何建议,我是 wordpress 新手
【问题讨论】:
标签: php mysql magento custom-post-type