我正在用wordpress开发网站,以防我的问题我想从主页上删除h1和h2标签。我想得到唯一的孩子p标签get_the_content()
<p id="main">
<?php
echo wp_trim_words(get_the_content(),20, \'...\' ); ?>
</p>
主页获取此页的内容
<h1 class="entry-title">Set and Furniture Design</h1>
<h2 class="green-pd">Set Design</h2>
<p id="para">A Bachelor pad was to be designed for a cookery show called \'Cook na kaho\' for the Star One TV channel. Props for same were purchased from various home stores and the set was installed with in four days of starting work.</p>
<h2 class="green-pd">Furniture Design</h2>
<p>The 600mm X 1500mm rectangular centre table used the Indian screen called jaaliwork as supports to the table top for breaking the monotony of solidity and straight lines.</p>
请帮帮我
非常感谢。
最合适的回答,由SO网友:Bhagchandani 整理而成
Wordpress功能get_the_content 自动从内容中删除html标记,因此仅获取p 使用此功能无法实现标记内容。您可以使用post excerpt 以满足您的要求。
Each post has section in admin called Excerpt<如果您无法在管理中看到该部分,请检查screen option 编辑帖子时
$my_excerpt = get_the_excerpt();