好的,我现在有这段代码。
<?php
query_posts('category_name=widgets2');
echo "<div id='widgets-wrapper2'><div id='marginwidgets' style='overflow: auto; max- width: 100%; height: 450px; max-height: 100%; margin: 0 auto;'>";
while (have_posts()) : the_post();
echo "<div class='thewidgets2'>";
echo wp_trim_words( the_content(), $num_words = 0, $more = "..." );
echo '<div style="height: 20px;"></div><a class="button2" href="'.get_permalink().'">Read More</a></div>';
endwhile;
echo "</div></div>";
?>如您所见,它从类别名widgets2获取所有帖子,然后应该会显示这些帖子。
这一行
echo wp_trim_words( the_content(), $num_words = 100, $more = "..." );应该将the_content()中的单词修剪为100,并在末尾字符处添加摘录,但不幸的是,它不起作用,它只显示看起来未修剪的整个内容。
希望这里的人能弄明白。我是开放的任何建议,建议和所有相关的想法,谢谢。
发布于 2012-10-16 06:57:13
因为WordPress函数the_content()回显内容。请改用函数get_the_content()。
发布于 2012-10-16 06:57:23
PHP免责声明--我对WordPress没有太多的经验(但我知道你在使用
)
原生PHP解决方案也可能在这方面对您有所帮助。substr()函数返回字符串的一部分-
echo substr($longContent, 0, $numOfChars) . '...';参考资料-
substr()https://stackoverflow.com/questions/12905031
复制相似问题