- This topic is empty.
-
AuthorPosts
-
April 11, 2012 at 8:06 am #37587KralleParticipant
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,
KralleApril 11, 2012 at 1:43 pm #101030schemeMemberbasename($_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.
April 11, 2012 at 5:51 pm #101048KralleParticipantHow 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,
KralleApril 11, 2012 at 8:22 pm #101054KristMemberDude.. 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 '';
}
?>
April 24, 2012 at 11:24 am #101705KralleParticipantYou, sir, are a legend. Thanks a bunch man. It works perfectly!
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.