2011-07-27 71 views
0

目前我的wordpress主题显示了主页上的帖子中的所有单词,甚至很长的帖子。我想将其限制在一个合理的数字上,让最多1500个单词显示在主页上,然后在下面应该有一个“阅读更多”链接。 我使用工具箱主题继承人1. content.php和2 index.php。限制wordpress博客主页上显示的帖子的字数

1. http://i.stack.imgur.com/rUWZv.png 
2. http://i.stack.imgur.com/YrZGS.png 

回答

0

您可以在wordpress所见即所得中使用'insert more tag'。

否则,你可以使用这样的事情来限制字数:(因为我没有时间来测试它以此为伪现在)

//define the number of words 
$length = 1500; 
$text = "Lorem Ipsum dolar sit amet etc etc"; //this would contain the article you are pulling from the database and syntax will depend largely on your theme. 

$shortened = implode(' ',array_slice(str_word_count($text,1),0,$length)); 

echo $shortened . ' ...'; 

然后链接到文章:

<a href="<?php the_permalink(); ?>">read more</a> 
相关问题