首页 > 解决方案 > 在 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();
?>

标签: phpwordpress

解决方案


请使用the_content()而不是get_the_content().

因为get_the_content()不通过 the_content 传递内容。这意味着它不会自动嵌入视频或扩展短代码等。

如需更多帮助,请参阅此链接:get_the_contentthe_content

我希望它会帮助你。谢谢 :)


推荐阅读