Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Beginner questions

Featured Replies

Hi,

 

I have been making some web pages as a hobby. I have learnt the basics of HTML, CSS. PHP and so on. So far i have been able to realize most of the things i have tried but i know that my code is far from best practice.

 

I have a couple of basic questions.

 

Regarding headers and footers. Since they look the same and appear on all pages what is the best way to add them to all of my pages?

I have done this with PHP before. Is this the way to do it?

 

Regarding a main menu. This is also something that i want to appear on all of my pages. However i want the link to the current page to be highlighted. How do i do this dynamically? Previously i have been adding the menu code manually to all of my pages and just changing the class for the link that corresponds to the current page. But it is just so much work every time i want to make a change in the menu having to do it on every page.

 

I guess this is it for now.

 

Regards

Rafal

If you've got this far it might be a good idea to get into a CMS, which have these kind of things out of the box for you. The way I did this when I was making raw php websites was to set a variable at the top of each page, and use it thusly:

 

<?php $page = 'home'; ?>
<?php include 'header.php'; ?>

 

Then in your header file it would look like:

 

<ul>
 <li><a href="#" <?php if($page == 'home'): ?> class="active" <?php endif; ?>>Home</a></li>
 <li><a href="#" <?php if($page == 'about'): ?> class="active" <?php endif; ?>>About</a></li>
 <li><a href="#" <?php if($page == 'contact'): ?> class="active" <?php endif; ?>>Contact</a></li>
</ul>

 

May not be the most efficient way, but it worked for me. But, like I say start using a CMS and you don't need to worry about it!

 

(I love the word 'thusly')

Edited by mrchristoph

  • Author

If you've got this far it might be a good idea to get into a CMS, which have these kind of things out of the box for you. The way I did this when I was making raw php websites was to set a variable at the top of each page, and use it thusly:

 

<?php $page = 'home'; ?>
<?php include 'header.php'; ?>

 

Then in your header file it would look like:

 

<ul>
 <li><a href="#" <?php if($page == 'home'): ?> class="active" <?php endif; ?>>Home</a></li>
 <li><a href="#" <?php if($page == 'about'): ?> class="active" <?php endif; ?>>About</a></li>
 <li><a href="#" <?php if($page == 'contact'): ?> class="active" <?php endif; ?>>Contact</a></li>
</ul>

 

May not be the most efficient way, but it worked for me. But, like I say start using a CMS and you don't need to worry about it!

 

(I love the word 'thusly')

 

Thanks for you quick reply. I have tried doing it in a similiar way in PHP. I was just not sure if PHP is the way to go or if there are better solutions.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.