Chr*_*yne 1 wordpress woocommerce
我将WooCommerce与WordPress结合使用来建立古董照片商店。
我正在使用WooCommerce产品属性功能来存储有关项目摄影师的信息。
参见此处的示例,在左侧http://bit.ly/1Dp999O的框中拉出了摄影师属性。
提取属性的代码如下所示:
if($attribute['is_taxonomy']) {
$values=wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
echo apply_filters('woocommerce_attribute', wpautop(wptexturize(implode(', ', $values))), $attribute, $values);
}
Run Code Online (Sandbox Code Playgroud)
$ values看起来像这样:
Array ( [0] => Photographer 1 )
Run Code Online (Sandbox Code Playgroud)
问题是,如何到达由WordPress和WooCommerce自动生成的摄影师的永久链接:http : //bit.ly/1JtwBna
我在WooCommerce中找不到与此相关的任何文档,这似乎是分类法中的一种分类法,它比stabdard WordPress还要远,但是我认为这是一个相当标准的要求。任何指针表示赞赏。
一旦有了属性术语(在这种情况下,是摄影师的名字),就可以get_term_link()用来获取URL。因为$productid没有传递到woocommerce_attribute文件夹,所以我不能过滤它,而是创建product-attributes.php模板的替代。并将相关部分修改为以下内容:
if ( $attribute['is_taxonomy'] ) {
$terms = wc_get_product_terms( $product->id, $attribute['name'], array( 'fields' => 'all' ) );
$html = '';
$counter = 1;
$total = count( $terms );
foreach( $terms as $term ){
$html .= sprintf( '<a href="%s" title="Permalink to %s">%s</a>',
esc_url( get_term_link( $term ) ),
esc_attr( $term->name ),
wptexturize( $term->name )
);
if( $counter < $total ){
$html .= ', ';
}
$counter++;
}
echo wpautop( $html );
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,URL并不是一个永久的链接。已经很晚了,我无法确定这是否与我的配置有关,或者确切地与它有关,但这只是一个开始。
| 归档时间: |
|
| 查看次数: |
3763 次 |
| 最近记录: |