Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get closest parent to root?
#1
Hi, I want to make my own extra page class, in addition to get_page_slug(), something like another CMS has, called rootParent--basically it will echo the closest parent to root, so I can add CSS classes section-by-section. Possible? Thanks.
Reply
#2
yup
You can add custom functions in function.php file located in your theme directory, and call those functions from within template.
Wiki contains all needed info.
Addons: blue business theme, Online Visitors, Notepad
Reply
#3
I'd also like to know what the best way is to get the root parent's slug, at the moment I'm just grabbing the document's parent. I'd imagine it uses menu_data().

PHP Code:
<?php // so the syntax is highlighted correctly ?>
<body
    id="d-<?php get_page_slug(); ?>"
    class="p-<?php echo (get_parent(false) != '') ? get_parent(false) : 'orphan' ?>"> 
Modern UI Admin for GetSimple
Watch the demo. Install this plugin. Use this CSS. Enjoy.
Reply
#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
#5
Hmm...this would indicate that I was wrong to organize my site with Home as the parent of every page Big Grin
Reply
#6
lol
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#7
@maruchan

Then, change the while... line to:

PHP Code:
while (!in_array(returnPageField($slug,'parent'),array('','index'))) { 

(assuming that by "Home" you mean the index page)
Reply




Users browsing this thread: 1 Guest(s)