Drupal身体类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Drupal身体类相关的知识,希望对你有一定的参考价值。

  1. <?php
  2. /**
  3. * This snippet creates a <body> class and id for each page.
  4. *
  5. * - Class names are general, applying to a whole section of documents (e.g. admin or ).
  6. * - Id names are unique, applying to a single page.
  7. */
  8. // Remove any leading and trailing slashes.
  9. $uri_path = trim($_SERVER['REQUEST_URI'], '/');
  10. // Split up the remaining URI into an array, using '/' as delimiter.
  11. $uri_parts = explode('/', $uri_path);
  12.  
  13. // If the first part is empty, label both id and class 'main'.
  14. if ($uri_parts[0] == '') {
  15. $body_id = 'main';
  16. $body_class = 'main';
  17. }
  18. else {
  19. // Construct the id name from the full URI, replacing slashes with dashes.
  20. $body_id = str_replace('/','-', $uri_path);
  21. // Construct the class name from the first part of the URI only.
  22. $body_class = $uri_parts[0];
  23. }
  24. /**
  25. * Add prefixes to create a kind of protective namepace to prevent possible
  26. * conflict with other css selectors.
  27. *
  28. * - Prefix body ids with "page-"(since we use them to target a specific page).
  29. * - Prefix body classes with "section-"(since we use them to target a whole sections).
  30. */
  31. $body_id = 'page-'.$body_id;
  32. $body_class = 'section-'.$body_class;
  33. print "<body class="$body_class" id="$body_id"";
  34. print theme('onload_attribute');
  35. print ">";
  36. ?>

以上是关于Drupal身体类的主要内容,如果未能解决你的问题,请参考以下文章

Drupal身体类

Drupal 6个独特的身体类

php 删除身体类

PHP Wordpress身体类

PHP 过滤论文的身体类

只为IE添加身体类