Hi there, I use plain HTML. I don't use DreamWeaver, although perhaps that's the solution to my problem. I am trying to deploy a new website with the same header and footer across each page.. I could use server side includes, but I can't because the current page is highlighted in the header (using class "current"), ex: <li><a href="page1.html">Page1</a></li> <li class="current"><a href="page2.html">Page 2</a></li> <li><a href="page3.html">Page 3</a></li> I cannot use WordPress for this site. Is there some easier way to do this, aside from copying and pasting?
Ideally you'll need to change your pages to .php format and include them using PHP. <?php include "includedfile.php";?> You could alternatively use an iFrame, but then you'll run into compatibility issues with mobile devices. Not entirely sure if you could do it in jQuery...
Is using PHP for these sort of things a common practice? Just curious if I'm kind of "doing things wrong from the start". You know, like, sometimes I see a guy who spends 3 days hand-coding image sliders because he hasn't bothered taking the time to learn JQuery. I don't want to be that guy.
It depends on your project type. If you are using ASP, there'd be a different way to do it but since you're including .html files, I'm guessing you are trying to make the jump from static to dynamic content so PHP would be the best way for you to go. If you're including a navigation menu for example you could do it: <?php include "includes/navigation.php";?> PHP: Or <?php require('includes/navigation.php');?> PHP: Include will put out a warning message if the file cannot be loaded whereas require will throw out a fatal error and stop the script then and there if it cannot be loaded. But to prevent duplicates, you could do it this way: <?php require_once('includes/navigation.php');?> PHP: I tend to use the include just as personal preference. If you're using classes for current pages, I usually have that right at the top of the page like so: <?php $class="current"; include "includes/head.php"; ?> Content <?php include "includes/footer.php";?> PHP: Then in your navigation, check if the page class is current.
Thanks!! While discussing moving to dynamic PHP... Will Google penalize me for using PHP over raw HTML? I hope that's not OT, since I think anyone dealing with moving toward PHP from HTML would have that concern.
No, PHP is Pre Hypertext Processing, it runs pretty much on the server. HTML/CSS will still be your primary markup. PHP allows you to do the cool stuff like include files and run scripts, connect to a database etc. It's seriously interesting to get into, just be careful to learn modern PHP (PHP5) and not PHP4. An interesting statistic... If you Google "filetypehp" you get: If you Google "filetype:html" you get: A hell of a lot of websites use PHP, but surprisingly to me, there's more HTML files than PHP files on the web.
Thanks! Wow, I'm also surprised at how close that ratio is... But more than PHP is so close to HTML. Thanks for your help!
Remember that with 'seo friendly' URL's doing redirect tricks via htaccess and their kin, that said google check is going to be meaningless for many sites now. For example: https://forums.digitalpoint.com/threads/how-to-deal-with-headers-and-footers-includes.2633007/ That's not going to show up as filetypehp, is it?
I recommend PHP. Maybe it can sounds "complicated", but its not. PHP is very friendly and you can find examples of every single function or step in Google in tons og pages. I learned PHP browsing in Google for doing everything, PHP its very easy and fun. In this particular case, you can use the PHP includes.