WordPress:get_the_content()和the_content()之间的区别

帕维尔·莫尔恰诺夫(Pavel Molchanov)

我正在研究WordPress中的新主题,并花费大量时间使用get_the_content()函数。

  <div class="clearfix">
      <div>
        <p><?=get_the_content();?></p>
      </div>
  </div>

似乎它不处理快捷方式,也不处理段落。

然后我用the_content()替换了它;我的段落和快捷方式开始起作用。

  <div class="clearfix">
      <div>
        <p><?=the_content();?></p>
      </div>
  </div>

我的问题:函数之间有什么区别以及需要进行哪些额外的处理the_content(); 与get_the_content();比较?

Xhynk

尽管@J Quest提供了适当的答案,但我想详细说明一下。一般来说,WordPress具有两种类型的后变量函数:get_函数和the_函数。

get_功能,例如get_the_content()get_the_ID()将返回所需的信息,然后必须对其进行操作并打印到页面上。一些例子:

$content = get_the_content();
$content = apply_filters( 'the_content', $content );
$content = str_replace( 'foo', 'bar', $content );

echo 'Post #'. get_the_ID() . $content;

the_函数,例如返回值the_content()the_ID()实际上echo返回的值,如果适用,将对适当的值应用“默认过滤器”。这些功能不需要回显。

echo get_the_ID();

在功能上与

the_ID();

如果您查看文档,the_ID()就会发现它只是输出的值get_the_ID()从来源:

function the_ID() {
    echo get_the_ID();
}

因此,如果您尝试将the_函数设置为变量,则会在整个页面中留下回显变量的痕迹。

$id = the_ID();
echo 'Post ID: '.$id;

将输出:

123Post ID: 123

要使用get_the_content()并使短代码运行,您要么需要通过do_shortcode()函数运行它,要么更好地进行the_content过滤。

$content = get_the_content();

echo do_shortcode( $content );
// Or:    
echo apply_filters( 'the_content', $content );

如果您只需要在模板中吐出帖子内容,而无需进行任何操作,通常最好使用(没有echo或echo short标签):

the_content();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

get_the_content()和无限嵌套循环中的wordpress简码

WordPress的the_content(); 显示内容和附件

了解wordpress the_content

自定义WordPress的get_the_content(); 退货

删除显示在 get_the_content 中的 URL

wordpress-如果bbpress显示the_content()

在wordpress插件上使用the_content钩子

Wordpress PHP短代码,ID的get_the_content不会显示自定义帖子类型的内容

Intent.ACTION_GET_CONTENT和Intent.ACTION_PICK之间的区别

ACTION_GET_CONTENT和ACTION_OPEN_DOCUMENT之间的真正区别是什么?

有条件的“ the_content”过滤器wordpress

wordpress the_content()未在正确的div中显示

需要从the_content()获取所有<img>;在WordPress中?

从 WordPress 中的“the_content”功能中剪切文本

在 WordPress 中 the_content() 前后添加内联图标

Wordpress the_content()输出文档类型声明

从 the_content WordPress 中删除带有 ID 的 div

如何在WordPress中分离帖子的the_content

WordPress 将 php 代码运行到 the_content 循环中

IBM Content Navigator:NonServiceLogger和ServiceLogger之间的区别

Polymer::host和:: content CSS选择器之间的区别

the_excerpt和the_content过滤器

the_content()在div外部显示

如何将get_the_content()中的原始数据用作变量

在CSS中,“ width:fit-content;”之间有什么区别?和“ width:“ fit-content(some_value);”?

通过ID获取the_content并在WordPress中保留<p> -tag

WordPress:front-page.php上的the_content过滤器

EmberJS中的[],@ each,content和<arrayName>之间有什么区别?

content-type:text / json和application / json之间的确切区别是什么?