GeekerCode更好的WordPress主题,值得信任的WordPress主题开发商

极美的主题、极致的插件

WordPress获取文章内容函数:the_content()与get_the_content()

摘要:wordpress the_content()函数模板标签 the_content() 显示当前文章的内容。该标签必须在 WordPress 主循环(loop)中,该标签必须在 WordPress 主循环(loop)中。若文章使用快速标签

wordpress the_content()函数

模板标签 the_content() 显示当前文章的内容。该标签必须在 WordPress 主循环(loop)中,该标签必须在 WordPress 主循环(loop)中。若文章使用快速标签 来截取摘要,the_content()标签将只在非单篇文章或非固定链接文章上显示前的摘要部分。the_content()标签可包含一个规定内容和样式的参数,该参数会生成“继续阅读全文”的链接。

关于 <span id="more-1093"></span> 标签有以下规定:

<!--more-->快速标签中的more前不得有空格。否则<!--more-->将无法发挥作用。

<!--more-->快速标签无法在模板中运行(会被模板忽略),如single.php只会显示一篇文章。

用法:

<?php the_content( $more_link_text, $strip_teaser, $more_file ); ?>

$more_link_text:

(字符串)(可选)"more"链接的链接文本,

默认值: '(more…)'

$strip_teaser:

(布尔型)(可选)显示(FALSE)或隐藏(TRUE)more链接前的文本。默认值:FALSE

$more_file:

(字符串)(可选)more链接所指向的文件

默认值:当前文件

使用以下方式在“More”中加入标题,在the_title()标签和display参数的帮助下,若文章使用 ,该示例可以显示”Continue reading ACTUAL POST TITLE”(继续阅读当前文章标题)。

<?php the_content("Continue reading " . the_title('', '', false)); ?> 

如果the_content()不能按计划运行(如当你希望显示 标签前的内容,the_content()却显示了全文内容),你可以用全局变量$more改写这一行为:

<?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...");
?>

wordpress get_the_content()函数

你可以用get_the_content函数返回文章内容的值,而非直接输出文章内容。示例如下:

<?php $content = get_the_content(); ?> 

请注意!get_the_content 无法进行以下操作,因此你最好手动添加以下代码,直到核心程序升级成功:

<?php
 
$content = apply_filters('the_content', $content);
 
$content = str_replace(']]>', ']]>', $content);
 
?>

the_content()位于wp-includes/post-template.php

建站!你有充足的理由选择我们

世界上超过30%的网站是由WordPress搭建,而我们是国内最靠谱的WordPress主题开发商
QQ咨询在线咨询问答互助微信号geekercode微信公众号云服务器