我有一个类别叫'新闻'。类别ID是'20'。我使用Divi(Divi子)主题+ Wordpress,并希望缩短新闻类别的摘录。Wordpress + Divi主题:根据类别控制摘录长度?
我通常会使用 '的add_filter' 功能是这样的:
<pre>
add_filter('excerpt_length', 'news_excerpt_length');
function news_excerpt_length($length) {
if(in_category(20)) {
return 30;
} else {
return 60;
}
}
</pre>
但不是干活的。我在'main-modules.php'中找到了摘录控件,并在这里添加我的过滤器?有没有人做过这个?
我加入了“主module.php”我的孩子主题的根目录,然后将此添加到我的孩子“的functions.php”
<pre>
if (! function_exists('et_builder_add_main_elements')) :
function et_builder_add_main_elements() {
require ET_BUILDER_DIR . 'main-structure-elements.php';
require 'main-modules.php';
do_action('et_builder_ready');
}
endif;
</pre>
它没有打破的主题,但它也没有工作。有没有人有任何这方面的经验?
- 谢谢!
最后的解决方案更容易维护。较少的编码。希望他们会改变这个文件是未来更新... – Benoti