如何列出GET_BODY_CLASS数组中的所有值

时间:2016-02-17 作者:Ben H

我试图列出当前所有的页面正文类。使用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>
";

1 个回复
最合适的回答,由SO网友:Apeiron 整理而成
$bodyclasses = get_body_class();
foreach ($bodyclasses as $class)
        echo $class;

相关推荐

如何在Functions.php中链接style.css

我是WordPress的新手;我刚开始学习WordPress。我想把风格联系起来。函数中的css。php,但我无法解决这里可能存在的问题。谁能给我指出正确的方向吗?指数php<?php get_header(); ?> <?php if ( have_posts() ) { while ( have_posts() ) { the_post();