CodeIgniter Forums
unique title, meta keyword, meta description for each page? how to - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: unique title, meta keyword, meta description for each page? how to (/showthread.php?tid=31408)



unique title, meta keyword, meta description for each page? how to - El Forum - 06-17-2010

[eluser]metaprinter[/eluser]
i’ve been handed a completed site that the client now wants to
1. have unique title, meta keyword, meta description for each page.

right now it just looks like the View is calling a Header that has the title, meta keyword, meta description coded right into it (so it's the same on every single page of the site).


Can someone push me in the right direction on what i need to do here? ps. i have no idea what version of codeigniter this site was built on .

thanks


unique title, meta keyword, meta description for each page? how to - El Forum - 06-17-2010

[eluser]cahva[/eluser]
Its just matter of defining the title etc. in the controller for the specific pages. If content is coming from database, you should add title, description and keywords fields to the pages table.

If you have static pages(not coming from db) adding title, keywords and description should be simple like this:

Controller About
Code:
<?php
class About extends Controller {

    function About()
    {
        parent::Controller();
    }
    
    function index()
    {
        $data['title'] = 'About title';
        $data['keywords'] = 'some,keywords,here';
        $data['description'] = 'Snakeoil ltd. The best oil in the business';
        
        $this->load->vars($data);
        
        $this->load->view('header');
        $this->load->view('about');
        $this->load->view('footer');
    }
}

header view
Code:
<!DOCTYPE HTML>
&lt;head&gt;
&lt;title&gt;&lt;?php echo $title ?&gt;&lt;/title&gt;
&lt;meta name="description" content="&lt;?php echo $description ?&gt;"&gt;
&lt;meta name="keywords" content="&lt;?php echo $keywords ?&gt;"&gt;
&lt;/head&gt;
&lt;body&gt;
...

In the controller theres $this->load->vars($data) which will make $data['title'] shown as $title, $data['description'] shown as $description etc. in all views including header view.

You could also send the $data array to the header view:
Code:
$this->load->view('header',$data);

Either way will do.


unique title, meta keyword, meta description for each page? how to - El Forum - 06-17-2010

[eluser]metaprinter[/eluser]
the content is coming from a database (there are several hundred "pages"). more info would be helpful, but what you've told me is great. I think i can do this now.

...heh snakeoil


unique title, meta keyword, meta description for each page? how to - El Forum - 06-17-2010

[eluser]Slowcheetah[/eluser]
For example (quick and dirty);

the Model

Code:
function get_content($id) {
        $this->db->where('id', $id);
        $query = $this->db->get('content', 1);
        if ($query->num_rows() == 1) {
           $row = $query->row();
           return $row->text;
        }
    }

the controller

Code:
function index() {
        $this->load->model('content_model');
        $id = '32';
        $data['page_title'] = $this->content_model->get_content($id);
        $this->load->view('page', $data);
    }

the view

Code:
echo $page_title



unique title, meta keyword, meta description for each page? how to - El Forum - 06-22-2010

[eluser]metaprinter[/eluser]
Thanks i got this working...