Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get closest parent to root?
#4
Insert this at the beginning of your template, or in your theme's functions.php file (create it if it doesn't exist):

PHP Code:
<?php
function get_top_parent() {
  
$slug return_page_slug();
  while (
returnPageField($slug,'parent') != '') {
    
$slug returnPageField($slug,'parent');
  }
  echo 
$slug;
}
?>

Then use it in your template:
PHP Code:
<?php get_top_parent(); ?>

In your example, it could be like this:
PHP Code:
<?php // so that the syntax is highlighted correctly ?>
<body id="d-<?php get_page_slug(); ?>" class="p-<?php get_top_parent(); ?>"> 
Reply


Messages In This Thread
Get closest parent to root? - by maruchan - 2013-02-16, 04:42:11
RE: Get closest parent to root? - by yojoe - 2013-02-18, 18:44:47
RE: Get closest parent to root? - by sal - 2013-02-19, 14:08:28
RE: Get closest parent to root? - by Carlos - 2013-02-20, 06:14:08
RE: Get closest parent to root? - by maruchan - 2013-02-21, 03:34:31
RE: Get closest parent to root? - by shawn_a - 2013-02-21, 04:00:57
RE: Get closest parent to root? - by Carlos - 2013-02-21, 04:35:51



Users browsing this thread: 2 Guest(s)