Posts: 8
Threads: 3
Joined: Feb 2013
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.
Posts: 1,204
Threads: 30
Joined: Jun 2010
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
Posts: 161
Threads: 6
Joined: Jan 2010
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' ?>">
Posts: 3,491
Threads: 106
Joined: Mar 2010
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(); ?>">
Posts: 8
Threads: 3
Joined: Feb 2013
Hmm...this would indicate that I was wrong to organize my site with Home as the parent of every page
Posts: 6,266
Threads: 181
Joined: Sep 2011
Posts: 3,491
Threads: 106
Joined: Mar 2010
@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)