0

我对 Wordpress 编码很陌生,请耐心等待。

我的主页上有一个部分,列出了 2 个最近的博客文章。

如果文本超过三行,我的设计就会混乱。所以我想知道是否存在让我自动附加“继续阅读”并允许用户单击该链接以将他们带到完整博客文章的本机功能?

例如,这是我不想要的:

坏的

这就是我想要的,我在 Photoshop 中进行了设计,如果帖子长度超过 3 行文本,这就是我希望发生的事情。

好的

谢谢,如果需要,我会尽力澄清任何事情!

4

2 回答 2

1

而不是做线条,我会尝试寻找字符或单词。下面的示例使用字符。

不要相信我的话,因为它没有经过测试。

$character == 40; // number of characters to compare
if(mb_strlen( get_the_content() ) < $character){
the_content();
}else{
the_content('Continue Reading...')
}

如果您想将其与字数进行比较,您可以使用 str_word_count(get_the_content(), 0)

于 2013-09-17T01:22:55.750 回答
1

您需要显示摘录而不是完整的帖子。

代替:

<?php the_content(); ?>

和:

<?php the_excerpt(); ?>

现在要控制摘录的长度,您需要在您的 functions.php 文件中添加此代码段

http://pastebin.com/tncRhSL2

资料来源:http ://codex.wordpress.org/Function_Reference/the_excerpt

于 2013-09-17T04:56:16.300 回答