lundi 15 mars 2021

PHP, check which page is loaded and set unique in

PHP newbie here, looking for help once again!

I have a basic, static PHP website. I have been tasked to add a unique title and meta descriptions to each page (SEO optimization). However, with my little PHP knowledge and the site's layout, it's proving to be a difficult task.

I have an index.php file. All other pages are referencing this file to get their head, header and footer from it. The problem is that I now need to add unique meta and title tags to unique pages, but unsure how to do this since all head content is being fed from index.php

I believe I need to make an if statement to query which page is loaded and then I need to add special meta and title tags accordingly.

After some research, I think I should use $_SERVER tag, but I'm unsure how to proceed. Looking for any feedback, especially syntax demonstration. Thank you!

This is index.php

<?php
if($_GET['page']) {
    $PAGE = $_GET['page'];
    $TYPE = 'page';
}
else if($_GET['service']) {
    $PAGE =  $_GET['service'];
    $TYPE = 'service';
}
else {
    $PAGE = 'home';
}

?>
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, shrink-to-fit=no">
<meta name="format-detection" content="telephone=no">
<title>Morland Capital Partners | Planning Consultancy</title>
<meta name="description" content="Morland Capital Partners effectively provide the investment, planning consultancy and technical expertise for residential & commercial developments">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.typekit.net/unv2jej.css">
<link rel='stylesheet' href='css/bootstrap.css' type='text/css' media='all' />
<link rel='stylesheet' href='css/font-awesome.min.css' type='text/css' media='all' />
<link rel='stylesheet' href='css/offcanvas-jquery.css' type='text/css' media='all' />
<link rel='stylesheet' href='css/slick.css' type='text/css' media='all' />
<link rel='stylesheet' href='css/style.css' type='text/css' media='all' />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-TD890P8QW2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-TD890P8QW2');
</script>
</head>


<body class="page-<?=$PAGE;?>">


<header class="header-wrapper"><!-- Toggle: .with-search -->
    <div class="container-fluid">
        <div class="header relative">

            <?php // <div class="hamburger-menu"><a class="offmenu-trigger" href="javascript:void(0);" role="button"></a></div> ?>

            <div class="logo"><a href="?page=home"><img src="images/logo.svg" alt=""></a></div>

            <nav class="thenav">
                <ul class="nav">
                    <li class="subnav"><a href="#"><strong>Services</strong></a>
                        <div class="subnavs">
                        <ul class="subtable">
                          <li class="subcell">
                            <div class="subcell-title"><a href="?service=land-promotion.php"><strong>Land Promotion</strong></a></div>
                            <div class="subcell-title"><a href="?service=distressed-development-purchases.php"><strong>Distressed Development Purchases</strong></a></div>
                            <div class="subcell-title"><a href="?service=residential-developments.php"><strong>Residential Developments</strong></a></div>
                            <div class="subcell-title"><a href="?service=commercial-developments.php"><strong>Commercial Developments</strong></a></div>
                          </li>
                        </ul>
                    </div>
                    </li>
                    <li><a href="?page=about"><strong>About Us</strong></a></li>
                    <li class="active"><a href="?page=contact"><strong>Contact Us</strong></a></li>
                </ul>
            </nav>

        </div>


    </div>
</header>


<?php if(file_exists('pages/'.$PAGE.'.php') && $TYPE=='page') {
    include ('pages/'.$PAGE.'.php');
} elseif(file_exists('services/'.$PAGE) && $TYPE=='service') {
    include ('services/'.$PAGE);
} elseif(file_exists('pages/'.$PAGE.'.php')) {
    include ('pages/'.$PAGE.'.php');
} else {
    include ('pages/404.php');
} ?>


<?php /*  if($PAGE == 'contact') { ?><?php } else { ?><?php } */ ?>


<footer class="footline">
    <div class="container-fluid">

    <div class="planning">
        <ul>
            <li class="cell-1">Are you planning to increase your capital?</li>
            <li class="cell-2"><a class="btnew" href="?page=contact"><strong>Contact Us</strong></a></li>
        </ul>
    </div>

    <div class="footer-hr">
    <hr>
    </div>

    <div class="footer-bottom">
        <div class="row">
            <div class="col-sm-8">
                <div class="copyright">&copy; <?php echo date('Y');?> Morland Capital Partners. Registered Company No 12341500</div>
            </div><!-- /col -->
            <div class="col-sm-4">
                <div class="verve-align">
                    <span class="verve">
                        <a target="_blank" href="https://www.verve-design.co.uk">Website by</a>
                    </span>
                </div>
            </div><!-- /col -->
        </div><!-- /row -->
    </div>

    </div><!-- /container-fluid -->

</footer>



<?php include('offcanvas-jquery.php'); echo '<span class="offmenu-overlay"></span>';?>

<script type='text/javascript' src='js/jquery-3.4.1.min.js'></script>
<script type='text/javascript' src='js/jquery.inview.min.js'></script>
<script type='text/javascript' src='js/jquery.waypoints.min.js'></script>
<script type='text/javascript' src='js/offcanvas-jquery.js'></script>
<script type='text/javascript' src='js/slick.min.js'></script>
<script type='text/javascript' src='js/theme.js'></script>

</body>
</html>

Aucun commentaire:

Enregistrer un commentaire