我使用了wordpress,我在function.php上使用了这段代码 -
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt)." <a href='" .get_permalink($post->ID) ." ' class='".readmore."'>বিস্তারিত পড়ুন</a>";
echo $excerpt;
}
此代码发布后循环.php-
&#34; <?php echo excerpt('55'); ?>
&#34;
如果我将55更改为20然后我的网站的前贴词变为20个单词但是如果我使用60而不是55然后它不会变成60个单词,如果我减小大小那么单词会变小但是如果我扩大了尺寸,然后单词不按数量放大,55是最大值?
你能帮助我吗?请告诉我如何在我的主页上放置超过55个单词,网站链接为 - http://it-bari.com,主页上默认为55个单词,,,,,,,请帮帮我。感谢。
答案 0 :(得分:1)
function vaf_custom_excerpt_lengh( $length ) {
return 99; //This is the number of length you want to set as default excerpt length
}
add_filter( 'excerpt_length', 'vaf_custom_excerpt_lengh',10 );
//The last parameter 10 is the priority which by default is 10. Lower values means higher priority to execute earlier..(try with values less than 10 if it doesn't work)
答案 1 :(得分:0)
使用此功能,您可以过滤wordpress中的摘录。
function filter_function_name( $excerpt ) {
return substr($excerpt,0,55);
}
add_filter( 'get_the_excerpt', 'filter_function_name' );
使用此功能在任何页面中获取摘录。
the_excerpt();
我希望这对你有用。
答案 2 :(得分:0)
您正在使用的功能excerpt()
将限制默认摘录中的字数。
默认情况下,摘录限制为55个字。当你运行你的函数并传入20时,例如该函数采用默认的摘录并将其减少到20个单词。
你不能把字数减少到比第一位更多,这就是为什么55以上的数字对你不起作用。
相反,您希望过滤摘录中的单词数量并将其应用到主页。
将以下代码添加到functions.php:
function wpse_filter_excerpt_length( $length ) {
if ( is_front_page() ) {
return 60; // change this to number of words you want on homepage.
} else {
return $length;
}
}
add_filter( 'excerpt_length', 'wpse_filter_excerpt_length', 999 );
我上面添加的代码基于您在管理中设置首页(设置 - &gt;阅读)的假设。否则,将is_front_page()
替换为is_home()
。