Please tell me how it is possible in Codeigniter3 to add any data to the article title.

The title of the article goes like this:

<title><?=$page_title?></title> 

For example, the site has 2 pages:

1) site.ru/article.html

2) site.ru/article-2.html

I want to add the current year to the article-2.html page using the following year:

 <?php echo date('Y') ?> 

those. so that in the article - article.html the title remains the same as it was, and at article-2.html the information was added to the title (for example, a year)

Thank.

    2 answers 2

    The issue is resolved. In the controller after the header is displayed:

     $this->data['page_title'] = $post['title']; 

    Insert the following:

     if($this->uri->uri_string() == 'category/article-555.html'){ $this->data['page_title'] = $post['title'] .date('Y'); } 

    Where category / article-555.html is the necessary page for which you need to add some content at the end of the title

    • this is also possible, and if there are many such pages? mess up every write here) - Batan112
    • At the moment, it was the only way to solve it. Your option is not suitable, because it adds a year to all the headlines, and I only need to apply to certain articles - kate

    In the controller, add whatever you want to the title. And pass the data [] array into view.

      $data['title']="Название сайта ".date('Y'); //к примеру для одной страницы $this->load->view('view',$data); 

    And in all forms

     <title><?=$title?></title> 
    • Yes, but this is how the titles of all articles change; Use one view for output. Is it possible to add something by URL? - kate
    • Why should one article be displayed in one year and not in another? What is the criterion? - Batan112
    • I have $this->data['page_title'] = $post['title']; $this->load->view('view', $this->data); in the controller $this->data['page_title'] = $post['title']; $this->load->view('view', $this->data); $this->data['page_title'] = $post['title']; $this->load->view('view', $this->data); And in the output, <title><?=$page_title?></title> . output headers from the database for all articles. How to add something to the title using the URL or ID of the article, i.e. to add to the article a year, but only to one - kate
    • http_: //example.com/number? year = 2016 and you take the year variable from the GET array, if there is one - Batan112