Using includes for static pages
-
Note: no capital “P”. I have a contact form I created that sits in the root and is a hard-coded link into the WP navigation. I used the wp-blog-header.php include in the form to include the header, sidebar and footer of the regular WP site.
My question is this: I’m also using a dynamic sidebar – it relies on a conditional statement to change the background color of the nav links – so when someone is on a certain page (like “About”) then that one link is “lit up” so the end user knows what page they are on.
However, it looks like the WP conditionals don’t work for the contact page – most likely because it’s not within the WP area – it’s just calling in the goodies so it’s formatted the same. I can get the “Contact” link to light up – but when I do it *all* single page posts show up with the “Contact” link changed.
Since the “Contact” page sits outside of the WP installation, is there a way I can use the conditional statements to make it recognize the contact page, and highlight the link accordingly? Really, all I need is to somehow edit the body tag (which I can do – no problem) to reflect the page it’s on (which I’m having a problem with.
So, for example – what is *quasi* working is this:
<?php if (is_single()) { ?>
<body id=”single<?php the_ID(); ?> “>
<?php } else { ?>
<body>
<?php } ?>So, if it’s on a single page, it’ll look for the ID# of the page/post in question, and add it to the word “single” – making it look like `<body id=”single14″>. Since the Contact form doesn’t have an ID#, it’ll just show up as “single”, and I can edit it accordingly.
The problem is, “the_ID()” isn’t working – not for *any* page or post. Is this because it’s outside of the Loop? I can make the_title work (and all kinds of other things) but the_ID() refuses to work. Using the_title() ends up making the ID weird, because if there’s spaces in the title, then shey show up in the ID. I guess it doesn’t matter – but in the future, it could.
I there a better way to do this? Can WP assign classes and such to pages *outside* of WP?
The topic ‘Using includes for static pages’ is closed to new replies.