php - 在 WordPress 中获取其他页面的页面内容时.....内容在单行中显示没有标签
问题描述
我正在使用此代码,但它仅显示行中的内容....在此页面中有带有 h1 h2 和 p 等标签的内容
<?php
$your_query = new WP_Query( 'pagename=who-we-are' );
while ( $your_query->have_posts() ) : $your_query->the_post();
$content = wpautop(get_the_content());
$trimmed_content = wp_trim_words( $content, 100, NULL );
echo $trimmed_content;
endwhile;
wp_reset_postdata();
?>
解决方案
请使用the_content()
而不是get_the_content()
.
因为get_the_content()
不通过 the_content 传递内容。这意味着它不会自动嵌入视频或扩展短代码等。
如需更多帮助,请参阅此链接:get_the_content、the_content
我希望它会帮助你。谢谢 :)
推荐阅读
- python - 现代gl.error.Error:GLSL编译器失败
- prolog - Prolog数独错误,无论如何都返回false
- python - Python Dataframe 日期列 - 将格式更改为 yyyy-mm-dd
- sql - 如何查找两个日期之间的连续天数
- angular - 从 .obj 文件加载的可交互 3D 模型?
- javascript - Ionic:有什么方法可以实现非垂直拖放组件重新排序?
- variables - BitBake 中的变量范围如何工作
- python - Django Cassandra sync_cassandra 不同步模型
- java - 测试类的参数化
- codenameone - 编辑后如何在 iOS 上关闭 TextField 数字键盘?