CodeIgniter Forums
[split] Best way to load unique header and footer for each page? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: [split] Best way to load unique header and footer for each page? (/showthread.php?tid=72185)



[split] Best way to load unique header and footer for each page? - digitalprem - 11-15-2018

hello everyone. I want to create SEO plugin in codeigniter same as Yoast plugin for wordpress. But problem is how to create different header for every page for website more than 300+ pages. Is it possible that I would assign a unique id and than create custom header for every pages.


RE: [split] Best way to load unique header and footer for each page? - dave friend - 11-15-2018

As you've probably considered, it's easy to provide dynamically determined values to the header.

Controller

PHP Code:
$data['page_title'] = $title;
$data["description_meta"] = $meta_desc;
$data["keywords_meta"] = $meta_keys;

$this->load
        
->view('header'$data)
 
       ->view("main_content")
 
       ->view("footer"); 

The view file header.php

PHP Code:
<!doctype html>
<
html>
 
   <head>
 
       <title><?= $page_title?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="keywords" content="<?= $keywords_meta?>">
        <meta name="description" content="<?= $description_meta?>">
        <!--all the other head stuff needed or desired-->
    </head>
    <body> 

The hard part is determining what values to assign to $title, $meta_desc and $meta_keys.
I assume that's the question you're really asking.
The answer depends on several factors:
  1. How exactly the website produces pages?
    • How dynamic is page content?
    • How dynamic are page URLs?
  2. How explicit do you want to be with metadata?

Care to tell us about all that?


RE: [split] Best way to load unique header and footer for each page? - digitalprem - 11-17-2018

Oh thanks mate !!!!!
You saved my lot of time.