JAVA、PHP、前端、APP、网站开发 - 开发技术学习

开发技术学习 » 编程开发 » 模板标签-the_content()

模板标签-the_content()

此文被围观2960日期: 2013-10-13 分类 : 编程开发  标签:  ········
说明 该标签显示当前文章的内容。该标签必须在WordPress主循环(loop)。 若文章使用快速标签 来截取摘要,the_content()标签将只在非单篇文章或非固定链接文章上显示 前的摘要部分。the_content()标签可包含一个规定 内容和样式的参数,该参数会生成“继续阅读全文”的链接。 关于 快速标签中的more前不得有空格。否则 将无法发挥作用。 快速标签无法在模板中运行(会被模板忽略),如single.php只会显示一篇文章。 更多信息请见改变“Read More”的样式 用法 [php] <?php the_content( $more_link_text, $strip_teaser, $more_file ); ?> [/php] 参数 $more_link_text (字符串)(可选)“more”链接的链接文本 默认值: '(more...)' $strip_teaser (布尔型)(可选)显示(FALSE)或隐藏(TRUE)more链接前的文本。 默认值:FALSE $more_file (字符串)(可选)more链接所指向的文件 默认值:当前文件 示例 设计“More”文本 文章使用 快速标签时,显示文章内容并用"Read more..." 代替 后的内容。 [php] <?php the_content('Read more...'); ?> [/php] 在“More”中加入标题 该示例类似于上一个示例,但在the_title()标签和display参数的帮助下,若文章使用 ,该示例可以显示"Continue reading ACTUAL POST TITLE"(继续阅读当前文章标题) [php] <?php the_content("Continue reading " . the_title('', '', false)); ?> [/php] 改写存档/单个页面 如果the_content()不能按计划运行(如当你希望显示 标签前的内容,the_content()却显示了全文内容),你可以用全局变量$more改写这一行为: [php] <?php global $more; // Declare global $more (before the loop). $more = 0; // Set (inside the loop) to display content above the more tag. the_content("More..."); ?> [/php] 如果需要显示所有正文: [php] <?php global $more; // Declare global $more (before the loop). $more = 1; // Set (inside the loop) to display all content, including text below more. the_content(); ?> [/php] 其它用法 你可以用get_the_content函数返回文章内容的值,而非直接输出文章内容。示例如下: [php] <?php $content = get_the_content(); ?> [/php] 请注意!get_the_content 无法进行以下操作,因此你最好手动添加以下代码,直到核心程序升级成功: [php] <?php $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); ?> [/php] 历史记录 始见于WordPress 0.71版本 源文件 the_content()位于wp-includes/post-template.php

站点声明:部分内容源自互联网,为传播信息之用,如有侵权,请联系我们删除。

© Copyright 2011-2024 www.kfju.com. All Rights Reserved.
超级字帖 版权所有。蜀ICP备12031064号