2014-10-11 53 views
0

亲爱的StackOverflow朋友, 在Wordpress电子商店中,我们使用Woocommerce及其扩展插件Woocommerce Brand Addon。WordPresspress:摘录仅针对Woocommerce品牌页面

我想这个代码(位于functions.php中)被应用只Woocommerce品牌页面:代码,它的工作在Woocommerce品牌但它也适用于其他类别/档案

我玩'分类'和'包括',插入品牌的ID,但没有结果。这是我的最后一次尝试。

add_action('woocommerce_after_shop_loop_item_title', 'lk2_woocommerce_product_excerpt', 35, 2); 
if (!function_exists('lk2_woocommerce_product_excerpt')) 
{ 
function lk2_woocommerce_product_excerpt() 
{ 
$content_length = 20; 
global $post; 
$args = array(
'include'   => '120,121,122,123,124,125,126,127', 
'taxonomy'   => 'product_brand', 
); 
$content = $post->post_excerpt; 
$wordarray = explode(' ', $content, $content_length + 1); 
if(count($wordarray) > $content_length) : 
array_pop($wordarray); 
array_push($wordarray, '...'); 
$content = implode(' ', $wordarray); 
$content = force_balance_tags($content); 
endif; 
echo "<span class='excerpt'><p>$content</p></span>"; 
} 
} 

不幸的是,我们还没有购买域名,所以我不能告诉你一个链接。

我可以用css修复输出,但我更愿意直接从代码中解决。 你能帮我找到修复我的错误的方向吗?谢谢你的时间!

+0

“品牌”是一种分类吗?你不能在函数内使用条件逻辑吗? – helgatheviking 2014-10-11 21:45:08

+0

@helgatheviking抱歉提问,但什么是'taxonomy'? – Yang 2014-10-12 23:58:09

+0

[分类法](http://codex.wordpress.org/Taxonomies)是将事物分组在一起的一种方法。标签和类别是帖子的内置分类法。产品标签和产品类别是由WooCommerce创建的产品的分类标准。 – helgatheviking 2014-10-13 09:41:56

回答

0

感谢您的四面八方!这是代码,感谢大卫

add_action('woocommerce_after_shop_loop_item_title', 'lk_woocommerce_product_excerpt', 35, 2); 
if (!function_exists('lk_woocommerce_product_excerpt')){ 
    function lk_woocommerce_product_excerpt(){ 
     $content_length = 10; 
     if(get_query_var('product_brand')) 
      $content_length = 20; 
     global $post; 
     $content = $post->post_excerpt; 
     $wordarray = explode(' ', $content, $content_length + 1); 
     if(count($wordarray) > $content_length) : 
     array_pop($wordarray); 
     array_push($wordarray, '...'); 
     $content = implode(' ', $wordarray); 
     $content = force_balance_tags($content); 
     endif; 
     echo "<span class='excerpt'><p>$content</p></span>"; 
    } 
} 
+0

if(get_query_var('product_brand'))是什么我正在寻找 – Elena 2014-10-14 18:08:16

+0

'如果(is_taxonomy('product_brand'))'也应该工作。很高兴你在最后分类。 – helgatheviking 2014-10-14 21:27:05

0

这看起来似乎有了答案:If is custom post type

if (is_single() && is_post_type('product_brand')){ 
    //work magic 
} 
+0

您可以将其组合为'is_singular('product_brand')'。 – helgatheviking 2014-10-13 10:54:42

+0

谢谢keepkalm和@helgatheviking,这很有趣:我会在未来保留你的宝贵提示(但我无法成功地使用我的代码) – Elena 2014-10-14 18:12:42

相关问题