6 Replies - 354 Views - Last Post: 29 March 2020 - 08:21 AM

#1 ajetrumpet   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 19

navigation menu / style in 1 file instead of all files

Posted 26 March 2020 - 11:58 PM

hey guys,

I have a very nice navigation menu on the side of one of my pages, but it is quite long and I don't want to have the code on every one of my static PHP pages on the website. what is the standard practice to ''call'' the code from a central location and allow the nav menu to appear on every page without having to repeat the code behind each page? here's a portion of the code that I currently have:

<ul>		
<li> <a href="#Software">Software</a>		
	<ul>	
	<li> <a href="#DesktopApplications">Desktop Applications</a>	
		<ul>
		<li><a href="#">Access</a></li>
		<li><a href="#">Excel</a></li>
		</ul>
	</li>	
	<li><a href="#">Web Applications</a>	
		<ul>
		<li><a href="#">PHP</a></li>
		<li class="#"><a href="#">Python</a></li>
		</ul>
	</li>	
	</ul>	
</li>		
</ul>


thanks guys.

Is This A Good Question/Topic? 0
  • +

Replies To: navigation menu / style in 1 file instead of all files

#2 Ornstein   User is online

  • D.I.C Head

Reputation: 103
  • View blog
  • Posts: 210
  • Joined: 13-May 15

Re: navigation menu / style in 1 file instead of all files

Posted 27 March 2020 - 01:02 AM

Are you using views or any kind of template engine? (If not, you probably should be.)

At the bare minimum - if we're rolling like it's 2005 - you'd have a header and footer file (e.g. header.php and footer.php) which you would load using PHP's include or require function. The header file will have everything from the <html> tag, down to where each page's content begins; the footer file has everything from where the page content ends, to the </html> tag. In the majority of cases, your layout will be such that your menu can go in the header file (or you might have the menu HTML in its own file which is then included in the header file).

As for views and templates, you might just have to search around for one that appeals to you and/or is most appropriate for your particular project. Twig, Blade, Smarty, etc.
Was This Post Helpful? 0
  • +
  • -

#3 ajetrumpet   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 19

Re: navigation menu / style in 1 file instead of all files

Posted 27 March 2020 - 01:12 AM

View PostOrnstein, on 27 March 2020 - 02:02 AM, said:

In the majority of cases, your layout will be such that your menu can go in the header file (or you might have the menu HTML in its own file which is then included in the header file).

so with this, are you saying that my include functions would look like this in the main page's code?

//home page's content
<?php
   include(header.php);
?>

<body>
<!-- more content here -->
</body>

<?php
   include(footer.php);
?>

This post has been edited by ajetrumpet: 27 March 2020 - 01:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 Ornstein   User is online

  • D.I.C Head

Reputation: 103
  • View blog
  • Posts: 210
  • Joined: 13-May 15

Re: navigation menu / style in 1 file instead of all files

Posted 27 March 2020 - 01:19 AM

Something like that. The <body> tag would be in header.php and the </body> tag would be in footer.php.
Was This Post Helpful? 0
  • +
  • -

#5 ajetrumpet   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 19

Re: navigation menu / style in 1 file instead of all files

Posted 27 March 2020 - 10:26 AM

View PostOrnstein, on 27 March 2020 - 02:19 AM, said:

Something like that. The <body> tag would be in header.php and the </body> tag would be in footer.php.
so the only content that would NOT be in an external file would be inside the BODY tag? I guess that makes sense to me....
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4277
  • View blog
  • Posts: 13,545
  • Joined: 08-June 10

Re: navigation menu / style in 1 file instead of all files

Posted 29 March 2020 - 08:19 AM

Well, the page title ain't in the <body>...
Was This Post Helpful? 0
  • +
  • -

#7 ajetrumpet   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 09-November 19

Re: navigation menu / style in 1 file instead of all files

Posted 29 March 2020 - 08:21 AM

View PostDormilich, on 29 March 2020 - 09:19 AM, said:

Well, the page title ain't in the <body>...
i'm not sure I appreciate that sarcasm, Dormilich. =) but thanks anyway...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1