Question about same stuff on multiple pages

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 974 Views - Last Post: 08 August 2014 - 08:35 AM

#1 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Question about same stuff on multiple pages

Posted 01 August 2014 - 02:34 PM

So, I'd like to have the same menus and stuff on all my pages, but I don't want to have to go through every single page every time I add a new menu item or do something to these fixed things. I've experimented with the <iframe> tag, and it works, but the drop down menus are hidden unless you scroll down to see them, and I don't want to have to do that. Is there any way I can get around this?
Is This A Good Question/Topic? 0
  • +

Replies To: Question about same stuff on multiple pages

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4364
  • View blog
  • Posts: 12,182
  • Joined: 18-April 07

Re: Question about same stuff on multiple pages

Posted 01 August 2014 - 03:10 PM

I assume you are not working with some kind of server-side technology like PHP or ASP right? You are just doing HTML? If so, you can take a look at Javascript and it has the ability to "load" content into the page dynamically... assuming the content you are loading is from your own website. The technique is rather easy if you use a javascript library like jQuery, but it can be done with straight javascript too.

If you are using a server-side technology, let us know which it is and we can help you with that as well. Typically you "include" content from other files as your page is executed on the server. :)
Was This Post Helpful? 1
  • +
  • -

#3 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Re: Question about same stuff on multiple pages

Posted 01 August 2014 - 04:02 PM

Ah, right. I haven't touched much on Javascript or other languages yet. I'm mainly concentrating on getting the hang of HTML and CSS. But I think it may be time to start learning those other things, there just seems to be so much more you can do using them.
Was This Post Helpful? 0
  • +
  • -

#4 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 80
  • View blog
  • Posts: 575
  • Joined: 21-November 13

Re: Question about same stuff on multiple pages

Posted 03 August 2014 - 04:08 AM

Javascript is not the proper way to do it if you're concerned about search engines indexation. They need to see your links in the HTML.

Moreover, a Javascript-based inclusion will mean 2 consecutive requests : one for the page, then, when it's finished, one for the menu. You will probably see the menu blink and your layout reflow. Not nice, especially if you're using jQuery because it will then mean 3 requests : one for the page, one for jQuery, one for the menu. Really not pragmatic.

Using PHP to include content is easy

<?php include("path of the file"); ?>


Yes, that's it. You're done.

Although I can only advise you to learn Javascript, your priority should be the server-side language to my mind. You don't need to push it too far : there is very little to know about PHP to be able to make smart sites. And you're in luck : there are not as many compatibility issues than with Javascript, so you can focus on actually leaning programming.
Was This Post Helpful? 0
  • +
  • -

#5 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 07:50 AM

Okay, I've had a quick look at Javascript and PHP to see how to do this. I'm well aware that a quick look isn't as comprehensive as I would eventually require, but all I want for the moment is to sort this one thing out.

So, with Javascript, I managed to do a few things, but all sorts of weird things happened and I gave up for the moment with that. So I looked into PHP, it seemed to be much more elegant and simpler. I went to this page and copied and pasted the code from example 2.

I made a file called header.php (and changed the relevant text in the HTML file. It didn't work. So instead, I pasted the PHP directly into the HTML and it worked (sort of). And now I'm left wondering whether there's a special technique to creating a PHP file that I've missed in my few minutes of research, other than appending .php to the filename.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3640
  • View blog
  • Posts: 12,614
  • Joined: 12-December 12

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 08:06 AM

So did you read some of the links on the left of the site?
PHP Home, PHP Intro, PHP Install
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3640
  • View blog
  • Posts: 12,614
  • Joined: 12-December 12

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 08:11 AM

Typically you would install the XAMPP (or WAMP or LAMP) stack.
Was This Post Helpful? 0
  • +
  • -

#8 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 08:47 AM

View Postandrewsw, on 07 August 2014 - 08:06 AM, said:

So did you read some of the links on the left of the site?
PHP Home, PHP Intro, PHP Install


I did, and I went to the download page and was immediately inundated with loads of links and no clear indication which one I should click on (for a site that deals with web design you'd think they'd improve their navigation).

Anyway, once I'd managed to make it work in the HTML, I figured it wasn't necessary.
Was This Post Helpful? 0
  • +
  • -

#9 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 80
  • View blog
  • Posts: 575
  • Joined: 21-November 13

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 08:48 AM

View PostAtharron, on 07 August 2014 - 03:50 PM, said:

I'm left wondering whether there's a special technique to creating a PHP file that I've missed in my few minutes of research, other than appending .php to the filename.


Isn't that OK ? Your server needs to know whether or not it has to parse the files you query (it's faster to simply serve the file without having to open it and parse it even though there is no PHP code to execute in the file). The easiest way is to add the .php extension to the filename. If for some reason you don't want to name your file like that, you can get Apache to parse html files as PHP. Simply write AddType application/x-httpd-php .html in a .htaccess file.
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3640
  • View blog
  • Posts: 12,614
  • Joined: 12-December 12

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 08:56 AM

How are you testing? Are you running your pages on a live, hosted, site? Then you wouldn't need to install anything as nearly every web-host has some version of PHP running.

If you are testing locally, which is strongly advised, then you need to install PHP and a local web server. That's what the AMP stacks I mentioned do for you - install the Apache web-server, MySql and PHP. If you haven't done this then your PHP isn't working (locally).
Was This Post Helpful? 0
  • +
  • -

#11 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 01:25 PM

Okay, so I looked at a sample of this book and followed the instructions to the letter. It now seems to work (although there are a few issues, but nothing that can't be sorted out by starting from scratch. I think I'll go ahead and buy that book. I learnt HTML and CSS from Wrox and found it to be much better explained than anything I found for free on the web (and even better than the For Dummies series. Wrox seems to be a more comprehensive course, while For Dummies always seems like an introduction), so I'll get that one, and another to learn Javascript and maybe continue my education with other books form that publisher.
Was This Post Helpful? 0
  • +
  • -

#12 ge∅  Icon User is offline

  • D.I.C Addict

Reputation: 80
  • View blog
  • Posts: 575
  • Joined: 21-November 13

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 02:15 PM

The main thing you need to understand about PHP is that it's executed by the server. Sounds stupid but that's where beginners stumble over : the client/server relation, the possibilities of the different languages, how they relate to each other. As you have experienced with content inclusion : the piece of code is short and as simple as the src attribute of an iframe, but if you don't understand what a server is you can't do anything with it. It's more about general culture than about programming skills.
Was This Post Helpful? 0
  • +
  • -

#13 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 04:00 PM

I think I'm beginning to understand, but correct me if I'm wrong.

The server is the computer that holds the site, and the server side languages are executed on that computer and sent as HTML through the internet to the user's computer where the browser interprets it to pretty words and pictures. Whereas stuff like Javascript is interpreted by the browser. So that's why I couldn't use PHP before I downloaded it, because the browser doesn't interpret it.
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3640
  • View blog
  • Posts: 12,614
  • Joined: 12-December 12

Re: Question about same stuff on multiple pages

Posted 07 August 2014 - 04:08 PM

That is correct.
Was This Post Helpful? 0
  • +
  • -

#15 Atharron  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 63
  • Joined: 23-April 14

Re: Question about same stuff on multiple pages

Posted 08 August 2014 - 12:10 AM

Woo hoo! I'm learning stuff. So, server side languages are useful because once it is uploaded to a provider that can interpret that language, it will work on any user's computer so there should be no compatibility issues. Plus, it is faster because it is all translated it at the source rather being sent as HTML and code to be essentially interpreted twice by the browser? I think that sounds right. Any other benefits?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2