In single.php, $post->ID will normally be the current post ID when used in a post loop.
Thread Starter
jchris
(@jchris)
MichaelH
Thanks. But I would prefer the page id since that would take care of all categories I publish on each bake. The cleanest method for me would be to take the page id from, say index.phd, and put it in the <body id=”xxx”> in the single.php. Then all would work without any changes in styles or code.
Can you advice me on that?
Thread Starter
jchris
(@jchris)
Sorry – “bake”??? Should be “page”.
I have 3 different pages I post to, index, page1, page2.
You don’t really post to pages. You can create a Template that in turn is designed to display posts or Pages.
So not sure what you mean by page id.
Thread Starter
jchris
(@jchris)
Thanks for your help.
I have found the solution with the help of Derek Herman.
I will try to explain both problem and solution briefly here:
I have 3 pages. On each of them I publish in several categories in different positions.
Each page i visually represented by a tab. I style the current tab by matching the menu links to the <body id> of the page shown.
When the posts have a more-link I want to keep the same tab as current. The more-link uses the file single.php.
The solution is to test for the posts category and echo a suitable tag within the body-tag.
To qoute Derek:
if (in_category(13) || in_category(15)) { echo ’something’; }
I put this php code within the body-tag and the result is exactly what I wanted.
<body id="<?php if (in_category(13) || in_category(14) || in_category(15) || in_category(16) || in_category(17)) { echo ('inspiration'); }
elseif (in_category(9) || in_category(10) || in_category(11)) { echo ('programinfo'); }
else {echo ('news');} ?>">
My mistake: I didn’t realize that I was already within the post (and the loop). I also assumed that I only can test for category within the loop. Hence I went looking for a possibility to pass a “parent_page_id” to the body-tag in single.php.
I hope this can be of help to someone.