Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Show Specific Banners for Specific Pages

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #37587
    Kralle
    Participant

    Hello guys!

    I am in a need of a little PHP script for a static website I’m making. I’m not using any CMS, just a few includes for the footer, header, menu etc.

    On every single page there is a featured image/banner, and I’d like to use a little snippet in those specific pages to include the image based in the current page.

    Here is how it’s outlined:
    For instance, I have three images. When the ‘about.php’ is the current page, I want to display image number one, and when ‘contact.php’ is the current page, I want to display image number two. The third image is for the rest of all the pages. I was wondering if it’s possible to say something like (I have absolutely no PHP experience)


    if ($currentpage == 'about.php') {
    print("")
    },
    if ($currentpage == 'contact.php') {
    print("")
    },
    else {
    print("")
    }
    ?>

    I don’t know how to get the current page thingy. I’m using the following script to highlight the current menu item, and I was wondering if it’s possible to just customize that little bunch of code so it’ll work with the images.


    function activestate($pagename, $currentpage) {
    if ($pagename == $currentpage) {
    echo "current";
    }
    }
    ?>


    Thanks in advance.

    Best regards,
    Kralle

    #101030
    scheme
    Member

    basename($_SERVER)

    … should do what you’re looking for. I’m not really sure if this is safe (regarding SQL injections), but as you are using a static web page it won’t be a problem.

    #101048
    Kralle
    Participant

    How would I implement

    basename($_SERVER)

    in the image-code – or even better, how would you write the final code? I really appreciate your help.

    Thanks in advance,
    Kralle

    #101054
    Krist
    Member

    Dude.. Try this..


    $currentpage = substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"],"/")+1);

    if ($currentpage == 'page_1.php') {
    echo '';
    }
    elseif ($currentpage == 'page_2.php') {
    echo '';
    }
    elseif ($currentpage == 'page_3.php') {
    echo '';
    }
    else {
    echo '';
    }
    ?>
    #101705
    Kralle
    Participant

    You, sir, are a legend. Thanks a bunch man. It works perfectly!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.