我试图列出当前所有的页面正文类。使用body_class
它给我的功能class="[body classes were here]"
但是,我需要以纯文本的形式显示这些内容。我已经试过了get_body_class
函数,但它是一个数组。
我将如何从中提取当前页面/帖子正文类?
https://codex.wordpress.org/Function_Reference/body_classhttps://codex.wordpress.org/Function_Reference/get_body_class
当前代码:
$parentTitle = get_the_title($post->post_parent);
$parentID = get_the_ID($post->post_parent);
$currentTitle = get_the_title($post);
$currentID = get_the_ID();
$bodyclasses = get_body_class($post);
foreach ($bodyclasses as $currentBodyClass)
echo "
<div id=\'plugin-PageInfo\' class=\'clearfix\'>
<div id=\'plugin-PageInfo-click\'>
<i class=\'fa fa-cog\'></i>
</div>
<div id=\'slideOutContainer\'>
<div id=\'slideContent\'>"
. $parentTitle . $parentID . $currentTitle . $currentID . $currentBodyClass .
"</div>
</div>
</div>
";
修订后的工作代码:
$parentTitle = get_the_title($post->post_parent);
$parentID = get_the_ID($post->post_parent);
$currentTitle = get_the_title($post);
$currentID = get_the_ID();
$bodyclasses = get_body_class($post);
echo "
<div id=\'plugin-PageInfo\' class=\'clearfix\'>
<div id=\'plugin-PageInfo-click\'>
<i class=\'fa fa-cog\'></i>
</div>
<div id=\'slideOutContainer\'>
<div id=\'slideContent\'>"
. $parentTitle . $parentID . $currentTitle . $currentID .\'\';
foreach ($bodyclasses as $currentBodyClass) {
echo "$currentBodyClass<br />\\n";
}
echo "</div>
</div>
</div>
";