Standard header and footer for all pages

Asked

Viewed 1,823 times

1

On the site I’m doing, like most, the page header and footer never change, only the body content. With header and footer I mean the whole part that’s beyond the <body></body>.

What I’m doing is putting the following codes:

header.php (simplified)

<html>
    <head>
        <title>Título</title>
        <!-- Aqui também incluo scripts de css e js -->
    </head>
    <body>

footer.php (simplified)

    <!-- Incluo mais alguns scripts -->
    </body>
</html>

index.php (simplified)

<?php include 'header.php'; ?>
    <h1>Página</h1>
    <!-- Conteúdo -->
<?php include 'footer.php'; ?>

At first until it was very functional, I didn’t need to repeat code. It was a little confusing, especially in the organization of HTML, but it worked. The problem is now that the project is too big. There are many scripts that should only be loaded on certain pages, and it is not necessary to load them at all (including in header.php or footer.php). I would not like to put at the end of the body of each page as it could not control the loading order (very important when using js). If anyone knows any way around or solve the problem by library, etc. please help.

PS: I know there is Composer. I haven’t learned to use it yet, but I believe it can’t include header and footer, and if I can, I probably can’t choose which scripts will be loaded on each page (my scripts).

  • Not knowing the structure of the project is difficult, but you can associate the url (www.site.com/[QUALQUERCOISA]) and by javascript associate one to each

  • 1

    place a variable with the page name on each page. Ex: $pagina=noticias and in the header make a conditional if ($pagina=="noticias"){echo "<script ......}

  • 1

    Already tried to put tags </head><body> after the <?php include 'header.php; ?>' and remove them from the archive header?

  • It would also work @Vitoradriano, but I’ve already chosen to pass variables. Before giving include_once, I passed the page name. Then in header.php I checked for an array of pages and loaded each script as needed.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.