Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 26, 2012, 09:03:20 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Interested in joining the WebsiteBaker team?
For more Information read
here
or on our
new website
.
155553
Posts in
21715
Topics by
7737
Members
Latest Member:
gx-world
WebsiteBaker Community Forum
English
Archive (posts up to 2007)
(Moderator:
Argos
)
any way to assign a unique body id to each page?
Pages: [
1
]
Go Down
Author
Topic: any way to assign a unique body id to each page? (Read 2336 times)
dellington
Offline
Posts: 86
any way to assign a unique body id to each page?
«
on:
April 10, 2006, 12:35:48 PM »
I like the way the page settings let you assign individual keywords or descriptions to specific pages. It would be really grat if you could assign individual ids to the body tags as well. This is very useful when designing pages with css.
In typical html the body of the page usually begins with this tag:
Code:
<body>
If you want to assign a style in a css document only to a particular page, a very easy way to do it is by adding an attribute to the body tag, like this:
Code:
<body id="home">
It seems like it shouldn't be difficult to add this somehow to the page settings area, but I really have no idea how that stuff works. Has anyone done this?
Logged
pcwacht
Guest
Re: any way to assign a unique body id to each page?
«
Reply #1 on:
April 10, 2006, 02:01:33 PM »
Nope not yet, but have a look in your templates/index.php
There the tag <body> is started
Try something like :
<body id=<?php echo PAGE_ID; ?>>
instead of PAGE_ID you could try PAGE_NAME
Good luck,
John
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #2 on:
April 10, 2006, 02:26:18 PM »
Hey, great suggestion! This
sort of
works:
<body id="<?php echo PAGE_ID; ?>">
It returns just a number, so for my second page in my site it returns
body id="2"
, for the third page it returns
body id="3"
, etc. However it would certainly be more helpful to get the actual text used for the menu link to be the body id. I tried putting in PAGE_NAME but that didn't seem to be valid. All I got back was
body id="PAGE_NAME"
.
Is there a list somewhere of the PHP codes used by WB for various things? I've figured a lot out just by looking around and working on my own templates but I know there are more I just don't know about.
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #3 on:
April 10, 2006, 02:32:38 PM »
Gotta love trial-and-error...
Code:
<body id="
<?php
echo
MENU_TITLE
;
?>
">
returns the text displayed on the menu buttons, i.e. for my Product Features page I get this:
Code:
<body id="Product Features">
Which is
almost
what I need, however the id attribute can not have any spaces in it. It needs to be made lowercase and get a hyphen separator just like my filename gets, i.e. the URL for this page is product-features.php. So it would be really great if I could figure out how to get the body id to look the same, i.e.:
Code:
<body id="product-features">
Logged
pcwacht
Guest
Re: any way to assign a unique body id to each page?
«
Reply #4 on:
April 10, 2006, 02:47:04 PM »
Hmmm, change case to lowercase, replace spaces with hyphens...
Not tested, but I think you need something like:
I have placed the commands on diff lines, but it could be a one_liner
Code:
<?php
$class_id
=
MENU_TITLE
;
$class_id
=
strtolower
(
$class_id
);
$class_id
=
str_replace
(
" "
,
"-"
,
$class_id
);
echo
'<body id="'
.
$class_id
.
'">'
;
?>
The one_liner:
Code:
<body id="
<?php
echo
str_replace
(
" "
,
"-"
, (
strtolower
(
$class_id
));
?>
">
Have fun!
John
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #5 on:
April 10, 2006, 02:56:46 PM »
The multi-line code works, the single line one doesn't, but...
THANK YOU!!!
And in case you're curious, I got the following error when trying the single line code:
Code:
Parse error: syntax error, unexpected ';' in templates/main/index.php on line 40
Anyway the multi-line code works great, it produces exactly what I need:
Code:
<body id="product-features">
Logged
pcwacht
Guest
Re: any way to assign a unique body id to each page?
«
Reply #6 on:
April 10, 2006, 03:26:12 PM »
Litle typo, forgot a )
Code:
<body id="
<?php
echo
str_replace
(
" "
,
"-"
, (
strtolower
(
$class_id
)));
?>
">
Again, have fun....
John
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #7 on:
April 10, 2006, 03:40:42 PM »
I tried that version and I get this:
Code:
<body id="">
Logged
generic
Offline
Posts: 60
Re: any way to assign a unique body id to each page?
«
Reply #8 on:
April 10, 2006, 06:43:29 PM »
couldnt you add in a "code" section and put your code in there?
Logged
pcwacht
Guest
Re: any way to assign a unique body id to each page?
«
Reply #9 on:
April 10, 2006, 07:43:46 PM »
All good stuff comes in three....
Code:
<body id="
<?php
echo
str_replace
(
" "
,
"-"
, (
strtolower
(
MENU_TITLE
)));
?>
">
Mind you still didn't test it ....
John
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #10 on:
April 10, 2006, 09:41:45 PM »
That works! Thanks!
Logged
centran
Offline
Posts: 76
Re: any way to assign a unique body id to each page?
«
Reply #11 on:
April 11, 2006, 12:07:09 AM »
Quote from: dellington on April 10, 2006, 12:35:48 PM
I like the way the page settings let you assign individual keywords or descriptions to specific pages. It would be really grat if you could assign individual ids to the body tags as well.
It would be a nice feature to be able to have body tag info for each page. Right now the website I am working on has an error on every page becuase I have to call a javascript onload in the body tag. But, the onload only works for one page in the entire site.
The error doesn't break the site and I doubt people will notice it, but it would be nice to get rid of.
Logged
pcwacht
Guest
Re: any way to assign a unique body id to each page?
«
Reply #12 on:
April 11, 2006, 06:55:13 AM »
2 ways to handle this
1 duplicate your template
use one with and one without the onload in the bodytag and set the default to the one without and the page wich needs it with
2 use PAGE_ID in your template to determine when to use the onload
<?php
if (PAGE_ID==12) { // Set to pageid of the page you need
echo '<body>'; /// No onload needed
} else {
echo '<body onload.....>'; // The onload is needed
"
?>
John
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #13 on:
April 11, 2006, 12:43:34 PM »
John--you are so awesome with the custom php!
Logged
dellington
Offline
Posts: 86
Re: any way to assign a unique body id to each page?
«
Reply #14 on:
April 11, 2006, 12:46:29 PM »
Quote from: generic
couldnt you add in a "code" section and put your code in there?
I can see how that might work, if you left the body tag out of your index.php document and instead used a section block...but then you would have to create that section for every page in your site, just to supply the body tag (because it is a required tag for every page). It would certainly be much more of a hassle than simply using the php code John wrote. Pulling a unique body tag from the menu title is now automated and doesn't require any extra steps, ever.
I have never really set about learning php, but clearly there would be a lot of value in doing so!
Logged
centran
Offline
Posts: 76
Re: any way to assign a unique body id to each page?
«
Reply #15 on:
April 12, 2006, 11:21:23 PM »
Quote from: pcwacht on April 11, 2006, 06:55:13 AM
2 ways to handle this
1 duplicate your template
use one with and one without the onload in the bodytag and set the default to the one without and the page wich needs it with
2 use PAGE_ID in your template to determine when to use the onload
<?php
if (PAGE_ID==12) { // Set to pageid of the page you need
echo '<body>'; /// No onload needed
} else {
echo '<body onload.....>'; // The onload is needed
"
?>
John
I should have thought of that myself! Works great.
you need to call the onload like this onload="codeCall();"
Since the echo needs to be in quotes this causes a problem so you need to use the escape character before a quote inside a quote.
echo "<body onload=\"callCode();\">";
note the \ before the " inside the main quotes for the echo.
«
Last Edit: April 12, 2006, 11:25:22 PM by centran
»
Logged
pcwacht
Guest
Re: any way to assign a unique body id to each page?
«
Reply #16 on:
April 13, 2006, 11:19:13 AM »
Or use ' (single) for php and " (double) for javascript
Something like this:
echo '<body onload="callCode();">';
John
Logged
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
=> Security Announcements
=> Documentation
=> WebsiteBaker Website Showcase
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
=====> Modules / Extensions
===> Suggestions
===> Software bugs
=> Help & Support
=> Modules
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
=> jQuery
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
=> Archive (posts up to 2007)
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
=====> Module / Extensions
===> Vorschläge
===> Softwarefehler
===> Erfahrungs und Testberichte
=> Hilfe/Support
=> Module & Snippets
=> Templates & Design
=> Tutorials
=> jQuery
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...