2014-10-11 55 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

相關問題