【问题标题】:Woocommerce shop page product descriptionWoocommerce 商店页面产品描述
【发布时间】:2014-05-27 19:30:00
【问题描述】:

我将以下代码添加到我的 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 = 5;
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>";
}
}

我不希望该文本链接到我的标题,并且希望能够将文本左对齐并更改颜色。现在它采用与产品标题相同的 CSS。任何帮助将不胜感激!

【问题讨论】:

  • 您也可以将类附加到 p,而不是跨度。
  • @Sam 我该怎么做?我从别处复制了这段代码,谢谢!
  • &lt;span class='excerpt'&gt;&lt;p&gt;$content&lt;/p&gt;&lt;/span&gt;更改为&lt;p class='excerpt'&gt;$content&lt;/p&gt;
  • 谢谢@Sam!您知道如何将内容长度从使用单词更改为字符吗?
  • 需要获取内容字符串,然后返回部分字符串。这应该可以解决问题:wordpress.org/support/topic/limit-excerpt-length-by-characters

标签: php css wordpress woocommerce


【解决方案1】:

比如:

.excerpt{
text-align:left;
color:#fff;
font-size:10px;
font-family:verdana;
font-weight:normal;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多