Php woocommerce-查询具有相同标签的产品
我找到了一些关于如何实现这一点的文章,但它们没有为我输出任何数据。下面是一个例子:Php woocommerce-查询具有相同标签的产品,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我找到了一些关于如何实现这一点的文章,但它们没有为我输出任何数据。下面是一个例子: function woo_products_by_tags_shortcode( $atts, $content = null ) { // Get attribuets extract(shortcode_atts(array( "tags" => '' ), $atts)); ob_start(); // Define Query Argum
function woo_products_by_tags_shortcode( $atts, $content = null ) {
// Get attribuets
extract(shortcode_atts(array(
"tags" => ''
), $atts));
ob_start();
// Define Query Arguments
$args = array(
'post_type' => 'product',
'posts_per_page' => 5,
'product_tag' => $tags
);
// Create the new query
$loop = new WP_Query( $args );
// Get products number
$product_count = $loop->post_count;
// If results
if( $product_count > 0 ) :
echo '<ul class="products">';
// Start the loop
while ( $loop->have_posts() ) : $loop->the_post(); global $product;
global $post;
echo "<p>" . $thePostID = $post->post_title. " </p>";
if (has_post_thumbnail( $loop->post->ID ))
echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
else
echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />';
endwhile;
echo '</ul><!--/.products-->';
else :
_e('No product matching your criteria.');
endif; // endif $product_count > 0
echo ob_get_clean();
}
function-woo\u-products\u-by\u-tags\u-shortcode($atts,$content=null){
//获取属性
提取(短码)附件(数组)(
“标签”=>“
)美元(附件);;
ob_start();
//定义查询参数
$args=数组(
“post_类型”=>“产品”,
“每页帖子数”=>5,
“产品标签”=>$tags
);
//创建新查询
$loop=新的WP_查询($args);
//获取产品编号
$product\U count=$loop->post\U count;
//如果结果
如果($product_count>0):
echo';
//开始循环
while($loop->have_posts()):$loop->the_post();global$产品;
全球$员额;
echo“”$thePostID=$post->post_title。””;
如果(有帖子缩略图($loop->post->ID))
echo获取“发布”缩略图($loop->post->ID,“shop\u catalog”);
其他的
echo'plugin_url()。/assets/images/placeholder.png“alt=”“width=“”。$woocommerce->get_image_size('shop_catalog_image_width')。'px“height=“”。$woocommerce->get_image_size('shop_catalog_image_high')。'px”/>;
结束时;
回声“
”;
其他:
_e(“没有符合您标准的产品”);
endif;//endif$product\u count>0
echo ob_get_clean();
}
这段代码是一个短代码,我不想写出来并手动输入标签名。我想使用此函数在单个产品摘要之后连接到woocommerce\u。基本上我正在尝试实现
第一篇文章是当前文章。之后,最多还有3篇文章可见。查询需要查看当前产品的标签,在其中查找更多内容,并按产品类别排序输出