A while ago I had a great solution using dynamic title and meta tags, but for the life of me I can't remember how to do it.

My page structure goes something like this:

index.php

include('header.php");

body

include('footer.php');

In the header file I used to have include('meta.php'); which contained the info I needed to populate the title and meta tags. The were all page specific for example:

$meta['title'] = "this is my home page"; only displayed when index.php is active
$meta['title'] = "this is the second page"; only displayed when second.php is active

and the same with the keywords.....

Does anyone have any ideas, solutions or know exactly what im getting at?

Thanks in advance

    On each page set the $meta['title'] value before the header.php file is included, then just use

    <title><?php echo $meta['title']; ?></title>

    in your header.php file and it will change it to whatever the $meta['title'] is

      jay6390;10938274 wrote:

      On each page set the $meta['title'] value before the header.php file is included, then just use

      <title><?php echo $meta['title']; ?></title>

      in your header.php file and it will change it to whatever the $meta['title'] is

      I understand what you mean and would do that normally which of course is easy enough. But I have a lot of pages and it would be ideal to have a centralised file i can update when i need to. I thought again I need a sort of $get statement in the header file within the title tag but cant remember how to construct it,

        another one to add to that,

        some of it is coming back to me $title = "this is a home page" [index.php]; or similar statements like this contained within the meta.php file..... then

        In the header.
        This is where I fall foul:
        <title><?php if$isset "document taken from something" = [index.php] print the title ?></title>

        sorry not sure about the syntax but that a guess.

          Oh I see. Well you could have it all run through a single index file. For example
          index.php

          <?php
          
          $page = isset($_GET['p']) ? $_GET['p'] : 'index';
          
          switch($page) {
              case 'about':
                  $title = 'About page';
                  break;
              case 'contact':
                  $title = 'Contact us page';
                  break;
              default:
                  $page = 'index';
                  $title = 'Home page';
                  break;
          }
          
          include('header.php');
          include('content/'.$page.'.php');
          include('footer.php');
          

          Then to load the about page you would go to
          yourdomain.com/index.php?p=about
          you would also need a folder called content with the page content of about in the file about.php
          index would be index.php etc etc
          Also, in your header.php file you would use the title with

          <title><?php echo $title; ?></title>

            I like your suggestion a lot Jay and may need a little more guidance on how to achieve that concept. I would be very grateful if you were to add me to MSN.

              I've added you
              Basically you have to have names for your pages like about, index, contact. Then you call the pages using
              index.php?p=page_name_here
              This will then set the title based on the p value, and also include the content from the php file in the content folder called
              content/page_name_here.php

                jay6390;10938288 wrote:

                I've added you
                Basically you have to have names for your pages like about, index, contact. Then you call the pages using
                index.php?p=page_name_here
                This will then set the title based on the p value, and also include the content from the php file in the content folder called
                content/page_name_here.php

                another noobie question, im going to work on your suggestion, how would I call my links up you know in the <a href=" code and would i need to mod_rewrite to make search engine friendly urls?

                  You could use htaccess if you needed to although it's not really all that necessary
                  .htaccess

                  RewriteEngine On
                  RewriteBase /
                  RewriteRule ^/page/([\w]+) /index.php?p=$1 [L]
                  

                  Then you call the pages with
                  /page/about
                  /page/contact
                  and so on
                  as for the href, if you're doing it with the first example i gave, use
                  <a href="/index.php?p=about">About</a>
                  for the second, use
                  <a href="/page/about">About</a>
                  Due to the nature of the mod rewrite you can only use letters, numbers and underscores for the page names or it won't work

                    Write a Reply...