如何以类的形式跟踪页面的所有相关标记到<body>标记?我指的是Wordpress如何将以下内容放入页面的body类属性中:
home page page-id-12766 page-template page-template-page-home-php cufon2-disabled safari theme-*
这对Joomla模板开发非常有帮助。
提前谢谢。
发布于 2012-09-12 21:22:06
我不知道是否有任何开箱即用的解决方案。由于该站点的主要结构主要基于菜单结构,因此下面的代码片段可能会有用。这在template/mytemplate/index.php文件中使用。
<?php
$menu = &JSite::getMenu();
$active = $menu->getActive();
$pageclass= '' ;
//$currentpage = ''; //In case if wanted to get the alias of the current page in a later stage.
if( count($active->tree) > 0 ) {
foreach ($active->tree as $key => $value) {
$pageclass .= 'level-'.$key . ' pageid-'.$value. ' page-'.$menu->getItem($value)->alias ;
//$currentpage = $menu->getItem($value)->alias;
}
}
?>
<body class="<?php echo $pageclass; ?>">这将输出类似以下内容:
<body class="level-0 pageid-101 page-home">您可以使用$active变量中的各种值来改进这一点。
发布于 2012-09-12 22:22:49
以下是有关Body Class Function的一些信息
Wordpress如何确定使用它来应用哪些类可以在post-template.php中找到
您要查找的相关函数是此模板中的get_body_class。它实际上会运行一系列检查,以确定当前页面是否满足给定类的条件。它还在很大程度上依赖于Wordpress特定的函数调用来帮助做出决定。
https://stackoverflow.com/questions/12388024
复制相似问题