Support » Fixing WordPress » Determine when accessing page?

  • I can’t figure out how to determine when this page is being processed:

    I know that “projects” is post 5, but if($post->ID==7){do something} doesn’t work. It is essentially an index of custom post types. If I can determine when it is being loaded, I can fix the highlighting in the menus. Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • It is possible that the menus have already been processed before the page is known. If this is not the case, if (is_page(5)) {do something} should work.

    Thanks vtxyzzy. I tried that (I meant a 5 in the example above), but it doesn’t work.

    I ended up working around it by just setting a php variable in the php template file, before the header file is called. Probably not the simplest, but it works. Thanks for replying 🙂


    Actually, just in case anyone reads this… setting a php variable doesn’t work either, though I thought it would. So I still don’t have a good solution, but I’m done worrying about it.

    Out of curiosity, did you declare the variable global? That might make a difference.

    I tried that, and still no luck. Does the get_header() not act as an include? I thought for sure it would work, I’m a little mystified why it doesn’t. I couldn’t get it to pass a global variable at all to the header.

    get_header() is a function – not a standard php include. Where do you want to test for Page 5 and what do you want to do if it is Page 5?

    If it is a function, wouldn’t it have access to a global variable stated before the function?

    My project index page which is an index of a custom post type doesn’t have the “current-menu-item” in the main navigation. I can fix it like this (an example that does fix another page):

    <?php if($post->ID==7){?>
            <style type="text/css">
                #bottom_nav .menu-item-110 a {
                    color: #333;
        <?php } ?>

    But I can’t find anything to fit in the if statement that actually recognizes when it is on that page. I figured I could do basically the same thing with a php variable, but I haven’t gotten that to work either. Thanks for the help.

    Passing a variable works for me with this in the template before get_header():

    global $mctemp; $mctemp='woohoo';

    and this in header.php:

    global $mctemp; echo '<!-- MCTEMP=' . $mctemp . ' -->';

    Nice! That works! Thanks for helping me through that.

    I don’t think I added “global” inside the header last time. Many thanks, that is nice to have working!


Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Determine when accessing page?’ is closed to new replies.