• Resolved eldeuce

    (@eldeuce)


    Okay, so I know very little PHP, but I did some research and pieced together

    $domain = $_SERVER['HTTP_HOST'];
    $path = $_SERVER['SCRIPT_NAME'];
    $page_url = "http://" . $domain . $path;

    this allows me to echo $page_url and it tells me the URL of the page I am on. This works swimmingly on a static site, but when i use it on wordpress I always get http://www.doamin.com/index.php no matter what page I am on.

    Basically I need one header graphic for the Home page and I need a second header graphic for all interior pages. I am doing this with IDs on a H2 tag. I just need a way to tell the script what page I am on means which ID to put in the H2 tag, but if i can’t get $page_url to pull out the right url then I’m not sure how to do this.
    I am sure it’s an issue with mod_rewrite or something.

    Maybe there is another way of doing this?

    Thanks for the help

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You’re doing it the really hard way. Try this instead:

    if (is_home()) {
    echo 'This is the home page!';
    } else {
    echo 'This is NOT the home page!';
    }

    Simple, eh? These are called Conditional Tags in WordPress, and they’re handy for this sort of thing.

    Thread Starter eldeuce

    (@eldeuce)

    You made this way too easy 🙂

    Thread Starter eldeuce

    (@eldeuce)

    Maybe I spoke too soon.
    I have

    <?php
        if (is_home()) {
          echo '<h2 id="idxhdr">Welcome to the site</h2> ;
        } else {
          echo '<h2>' . the_title() . '</h2>';
        }
        ?>

    but when it parses, i get

    Page Title<h2></h2>

    Any idea what I did wrong?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    This line:
    echo '<h2>' . the_title() . '</h2>';

    Is what’s giving you the Page Title outside the h2 tags. Try this instead:

    echo '<h2>';
    the_title();
    echo '</h2>';

    Thread Starter eldeuce

    (@eldeuce)

    Worked like a champ.
    Thanks for your help. Those conditional statements have come in very handy for putting embedded video on certain pages (the code box wouldnt let me paste the code) and then i would able to php include forms on certain pages.

    Site is finally coming together… only took me 5 hours so far.

    Thread Starter eldeuce

    (@eldeuce)

    I keep talking too soon.
    Once I change the else statement to your way of writing it, it stops doing the correct header for the home page, now ever the home page has the secondary header.

    ….

    <?php
        if (is_home()) {
          echo '<h2 id="idxhdr">Home Page</h2> ';
        } else {
          echo '<h2>';
          the_title();
          echo '</h2>';
        }
        ?>

    Thread Starter eldeuce

    (@eldeuce)

    I just used

    is_page('home')

    and this works. I’ll just stick with this.
    Thanks for the help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘find what page I’m on’ is closed to new replies.