M
M
meltmestnt2018-07-28 16:07:17
PHP
meltmestnt, 2018-07-28 16:07:17

How are separate pages of the site created (in addition to the main one)?

Couldn't google anything on this topic. Interested in creating separate pages of the site in addition to the main main page.
For example, there is a main page with a menu, and when you navigate through the menu, other pages open: about us, catalog, etc.
I read a long time ago that no one writes HTML and CSS code for the header, footer, etc. for these pages, but inserts them into a new page using PHP. Still interested in the dynamic creation of pages like on forums, etc. I would like to read more about this. Any links to relevant information are welcome.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-07-28
@meltmestnt

Here is a very simple example for you.

Website root folder structure
++ static
+++ images
++++ logo.png
+ header.php
+ content.php
+ footer.php

header.php
<?php $logo_url = '/images/logo.png'; ?>
<header>
   <h2>Тут хэдер</h2>
   <p>А вот и лого:</p>
   <img src="<?=$logo_url;?>" alt="logo">
</header>
content.php
<?php
require 'header.php';
$page = !empty($_GET['page'])
   ? filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING)
   : 'index' ; ?>
<main>
   <?php if($page === 'index'): ?>
      <p>Главная страница сайта.</p>
   <?php else: ?>
      <p>Не главная страница сайта.</p>
      <a href="/">Перейти на главную</a>
   <?php endif; ?>
</main>
<?php require 'footer.php'; ?>
footer.php
<?php $copyright = 'Mr. Y'; ?>
<footer>
   <h4>Тут футер</h4>
   <p><?=$copyright;?></p>
</footer>

E
Eugene, 2018-07-28
@Eugeny1987

look towards CMS, for example HostCMS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question