the_content() 和 get_the_content() 的不同之处

如果你是一名WordPress开发者,你可能知道WordPress函数 the_content() 可以直接输出文章内容,而 get_the_content() 则需要在前面添加 echo 才可以输出文章内容。

<?php
the_content();

echo get_the_content();
?>

这是WordPress内置函数的一个很重要的标志,the_ 开头的函数直接输出,get_ 开头的函数不执行输出。

然而,两者的区别不仅如此:

  1. get_the_content()不会通过the_content传递内容 。这意味着它不会自动嵌入视频或扩展简码。所以,使用get_the_content(),它将删除嵌入和简码等标签。
  2. get_the_content() 获取的内容是原始保存的数据,不含段落标签 p,导致原本应该分段的内容,无法进行分段。也即是说 <?php echo get_the_content(); ?><?php the_content(); ?> 输出的内容是不一样的,前者会过滤掉很多标签。所以,如果你要输出正文的完整内容时,请使用 <?php the_content(); ?>

最近折腾的项目就遇到这个问题,这次才搞明白 <?php echo get_the_content(); ?><?php the_content(); ?> 是真的不一样的。

来源:

https://www.wpdaxue.com/the-difference-between-the-content-and-get-the-content.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32075.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?