【发布时间】:2014-04-14 15:12:06
【问题描述】:
我将以下代码添加到我的 functions.php 文件中,以便在我的商店页面的缩略图下添加简短的产品描述。
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 = 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>";
}
}
正如您在我的网站上看到的here,描述在那里,但长度基于单词。无论如何,我可以根据字符而不是单词来确定描述的内容长度吗?
【问题讨论】:
标签: php wordpress function woocommerce