Jump to content

Recommended Posts

Can anyone tell me what the best option for getting the dynamic title AND dynamic meta description on my particular site setup would be?

 

I have an index.php but all of the individual page content is stored in a subdirectory called \html\ it's stored as .html files and is called up as index.php?page=client_comments for example.

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

could you not save them as php files instead of html files? Then include define statements for your meta tags in the included files?

 

such as:

 

include file

define (META_TITLE, 'title of page');

 

 

then in your index.php have:

 

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

 

As long as you include the file before the the title brackets within the page.

 

I'm not sure, changing them to php might break the rest of my site.  My site integrates with a word press blog and an online store.  I could try it and see. 

 

Can you tell me what the steps would be to try it out?  I'm trying to do both the title and the meta descriptions.

 

How would I modify the html to make them php and how would i edit my index?

 

Thanks.

 

could you not save them as php files instead of html files? Then include define statements for your meta tags in the included files?

 

such as:

 

include file

define (META_TITLE, 'title of page');

 

 

then in your index.php have:

 

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

 

As long as you include the file before the the title brackets within the page.

You should be ok just changing the extension from .html to .php. I cant see there being many issues.

 

As for changing the index.php, just do as per my example. So for each title/meta tag you create a new define statement, making a relevant name for each item...

 

define(TITLE, 'title of page');
define(METATAGDESC, 'meta description');
etc
etc...

 

and then at the top of your index.php you call the relevant php file using whatever script you do currently. And as long as it is included before the head section of the index.php page you can use the php echo function to retrieve the define statements.

 

To retrieve the defines just echo their names within the <?php ?> brackets.

 

<title><?php echo TITLE ?></title>

 

If you get stuck then post some code and i'm sure if i dont get time to have a look somebody will.

 

good luck

I *think* I can figure this out but I'm still a little fuzzy on where and how I define the actual text that goes in the title and meta desc for each individual page.

 

Thanks!

 

if you get stuck then post some code, and i'll have a look.

 

But if you are calling individual files from your /html/ directory then in the individual files you should be putting your define statements. I'm not sure there would be any other way of doing it, short of having a /defines/ directory too and when you call your individual pages you call the relevant php defines page from the defines directory but i think that'll complicate things.

 

 

Well I got so far as switching everything over to php.  That worked fine.  Here is my index:

 

<?php

 

include "menu.inc.php";

 

function menu(){

global $_menu;

$str = '';

foreach($_menu as $url => $name){

    $sel = ($_GET['page'] == $url ) ? ' id="selected" ' : '';

    $str .= "<li ". $sel ."><a href='index.php?page=" . $url . "' >" . $name . "</a>\n";

}

  echo $str;

}

 

 

 

 

 

 

$page = ( isset($_GET['pg']) ?  $_GET['pg'] : ((isset($_GET['page']))? $_GET['page']:'home'));

 

$file = basename($page).'.php';

$html_path = "php/";

 

?>

 

but as soon as I added the line to call up my title which I defined in home.php the page broke and most of the content doesn't display.

 

I replaced the staticly defined title within the title tags like this:

 

<title><?php echo TITLE ?></title>

 

I don't really understand why it doesn't work.

Ok actually my mistake - it is adding the following to home.php that breaks it:

 

<?php

 

 

define(TITLE, 'Health Basics | The Website Of Andrea Stevens, M.S., C.N.S., C.M.T.A. Clinical Nutritionist');

define(METATAGDESC, 'Andrea Stevens is a clinical nutritionist specializing in consultations on digestive system dysfunction and children with neurological and developmental disorders as well as educational programs focusing on natural whole foods and wellness.  Health Basics is an international distributor of natural health products, vitamins and supplements.');

define(METAKEYWORDS, 'metabolic typing, body ecology, body ecology diet, digestive problems, digestive disorders, food sensitivities, dysbiosis, autism, asperberger syndrome, aspergers syndrome, asperger's syndrome, asperger, aspergers, asperger's, ASD, spectrum disorder, GI problems, GI disorders, gastrointestinal problems, gastrointestinal disorders, whole foods nutritionist, natural nutritionist, functional nutritionist, functional healthcare, organic foods, organic, holistic healing, holistic healthcare, digestive system disorders, candidiasis, candida, candida related problems, yeast related problems, yeast overgrowth, infant feeding, infant feeding problems, failure to thrive, children eating problems, children neurological problems, neurological problems, eating problems, seizures, behavior problems, learning problems, learning disabilities, learning disability, attention deficit disorder, ADD, attention deficit disorder, attention deficit hyperactivity disorder, ADHD, hyperactivity, hyperactivity disorder, DAN Protocol, leaky gut, crohns, crohn's, crohns disease, crohn's disease');

 

?>

 

Do you know what I'm doing wrong?

Here is the page source:

 

<?php

 

 

define(TITLE, 'Health Basics | The Website Of Andrea Stevens, M.S., C.N.S., C.M.T.A. Clinical Nutritionist');

define(METATAGDESC, 'Andrea Stevens is a clinical nutritionist specializing in consultations on digestive system dysfunction and children with neurological and developmental disorders as well as educational programs focusing on natural whole foods and wellness.  Health Basics is an international distributor of natural health products, vitamins and supplements.');

define(METAKEYWORDS, 'metabolic typing, body ecology, body ecology diet, digestive problems, digestive disorders, food sensitivities, dysbiosis, autism, asperberger syndrome, aspergers syndrome, asperger's syndrome, asperger, aspergers, asperger's, ASD, spectrum disorder, GI problems, GI disorders, gastrointestinal problems, gastrointestinal disorders, whole foods nutritionist, natural nutritionist, functional nutritionist, functional healthcare, organic foods, organic, holistic healing, holistic healthcare, digestive system disorders, candidiasis, candida, candida related problems, yeast related problems, yeast overgrowth, infant feeding, infant feeding problems, failure to thrive, children eating problems, children neurological problems, neurological problems, eating problems, seizures, behavior problems, learning problems, learning disabilities, learning disability, attention deficit disorder, ADD, attention deficit disorder, attention deficit hyperactivity disorder, ADHD, hyperactivity, hyperactivity disorder, DAN Protocol, leaky gut, crohns, crohn's, crohns disease, crohn's disease');

 

?>

 

 

<h2>Philosophy & Focus</h2>

      <p>My primary goal is to assist clients in achieving the highest degree of health possible for themselves and their families. Drawing upon up-to-date scientific findings as well as forgotten but highly valuable knowledge - which includes old-fashioned methods of food preparation - I enjoy helping others to use natural ways to support their health and avoid illness and disease. Prescription medication, with its highly undesirable side effects, should not be the first or primary method of addressing ill health.</p>

      <p><br />

        The human body is wonderfully designed with countless mechanisms to stay healthy and balanced. If we can provide the body with all the natural raw materials (an abundance of nutrients, pure water, clean air, and love and intimacy among them) that it needs, as well as support the elimination of waste material and toxins, the body can heal many conditions and increase its levels of health, energy and vitality.</p>

<p><br />

       

          <div class="box">

         

          <center><b><i><p>Essential Nutrients in... Waste out!</p>

          <p>This is a model that all living organisms follow in order to thrive and flourish.</p></b></i></center>

         

               

         

          </div>

              <p><br />

          <p>Before turning to over-the-counter and prescription medications - which primarily suppress symptoms instead of address the underlying causes of dysfunction - understanding, and then supporting, the natural processes of the body will often result in a marked decrease or elimination of those symptoms. Symptoms are nature's way of calling our attention to problems in the body. Perhaps we are meant to listen to those signals and then correct the habits in our lifestyle that contribute to the underlying dysfunction (which then results in specific symptoms). These habits usually involve failing to provide the body with enough of the raw materials it needs, and hampering its detoxification, or waste removal, pathways.</p>

          <p><br />

          <p>The answer to our health problems doesn't lie in treating (suppressing) symptoms, but in addressing the causes - which are generally some combination of nutritional deficiencies and waste buildup within the body.</p>

          <p><br />

          <p>Two major concepts govern my approach. The first is that of biochemical individuality, which states that no two people are exactly alike and, therefore, no one dietary program is best for everyone... the Metabolic Typing philosophy addresses this. Secondly, I believe - as most physicians did prior to the mid 20th century - that overall health is directly dependent upon the health of the gastrointestinal or digestive tract... the Body Ecology approach addresses this.</p>

          <p><br />

          <p>I hold a firm belief in the inherent power, wisdom, and uniqueness in each of us. Eating natural, unaltered whole foods grown or raised in a healthy and socially responsible manner, along with proper digestive system-processing of those foods, are key to achieving optimal health, energy and vitality.</p>

          <p><br />

       

          <div class="box">

         

          <center<b><i><p>We need to Understand the <b>BASICS</b> of Body Functioning and the <B>BASICS</B> of Health-Supporting Food in order to Achieve BASIC Good Health. </p></b></i></center>

       

         

               

         

          </div>

         

              <p><br />

             

              <p>Specific conditions which can be successfully treated through Whole Food Nutrition and Optimal Digestive System Functioning include:</p>

              <p><br />

              <p>Overt Digestive Problems</p>

             

                    <ul>

            <li>Infant and Child Feeding Problems</li>

            <li>Reflux/GERD</li>

      <li>Food Sensitivities, Allergies, Intolerances</li>

            <li>Heartburn/Indigestion</li>

            <li>Bloating/Gas</li>

            <li>Constipation</li>

      <li>Diarrhea / Loose Bowel Movements</li>

            <li>Irritable Bowel Syndrome (IBS)</li>

              </ul>

              <p><br />

             

            <p>Systemic Problems Related to an Underlying Unhealthy Digestive System</p>

            <ul>

            <li>Candidiasis</li>

            <li>Autism Spectrum Disorder</li>

            <li>Attention Deficit Disorder (ADD), Attention Deficit Hypactivity Disorder (ADHD) and other Behavior and Learning Problems</li>

      <li>Epilepsy and Seizures</li>

            <li>Autoimmune Conditions like Rheumatoid Arthritis, Lupus, Multiple Sclerosis</li>

            <li>Chronic Fatigue</li>

            <li>Fibromyalgia</li>

            <li>"Mysterious Medical Maladies" - conditions unable to be successfully diagnosed or treated within the traditional healthcare system</li>

           

              </ul>

              <p><br />

              <p>Prevention of Health Problems and Disease</p>

              <ul>

              <li>Pregnancy Preparation</li>

                <li>Pregnancy</li>

                  <li>Graceful Aging</li>

                    <li>Optimal Levels of Energy, Vitality and Health</li>

                   

              </ul>

             

             

 

 

<!-- START Google Analytics -->

 

<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>

<script type="text/javascript">

try {

var pageTracker = _gat._getTracker("UA-12299340-1");

pageTracker._setDomainName(".healthbasics.net");

pageTracker._trackPageview();

} catch(err) {}</script>

 

<!-- Google Analytics END -->

 

<!-- Start of StatCounter Code -->

<script type="text/javascript">

var sc_project=5441595;

var sc_invisible=1;

var sc_partition=54;

var sc_click_stat=1;

var sc_security="a84f73c6";

</script>

 

<script type="text/javascript"

src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div

class="statcounter"><a title="web analytics"

class="statcounter" href="http://www.statcounter.com/"><img

class="statcounter"

src="http://c.statcounter.com/5441595/0/a84f73c6/1/"

alt="web analytics" /></a></div></noscript>

<!-- End of StatCounter Code -->

 

 

[attachment deleted by admin]

You have single quotes (apostrophes) within a single quoted string. Either change the string enclosure quotes to double or escape the single quotes within.

I don't understand about hte single quotes.  But what I'm realizing is that my website doesn't like it if there is any php code in these "content" pages.  It is ok if I rename them .php but as soon as I put *ANY* php code in there, everything goes to hell in a handbasket and the page breaks like show in the screen shot.

 

 

I don't understand about hte single quotes.  But what I'm realizing is that my website doesn't like it if there is any php code in these "content" pages.  It is ok if I rename them .php but as soon as I put *ANY* php code in there, everything goes to hell in a handbasket and the page breaks like show in the screen shot.

 

lol. Don't panic.

 

Try changing all ' single quotes in the defines to " double quotes (might cause other issues) or use \ before every ' in your defines text. What this does is basically tells php to not class the ' as the end of the define statement.

Take it easy; PHP doesn't hate you, or anything like that. When a string is enclosed in quotes, you can't use the same quote within that string unless it is escaped, by preceding it with a backslash.

 

$string = "This is a \"string\" that is properly escaped";

$string = "This is a "string" that is not properly escaped";

$string = 'This is a \'string\' that is properly escaped';

$string = "This 'string' is just fine as it is";

$string = 'This  "string" is fine, also';

 

Well, I think you get the idea.

DO I need <?php echo $TITLE ?> maybe?

 

Nope, there is no need for the $ sign as its not a php variable as such.

 

Just make sure all quotes are escaped as pikachu has stated and you should find it starts working.

Take it easy; PHP doesn't hate you, or anything like that. When a string is enclosed in quotes, you can't use the same quote within that string unless it is escaped, by preceding it with a backslash.

 

$string = "This is a \"string\" that is properly escaped";

$string = "This is a "string" that is not properly escaped";

$string = 'This is a \'string\' that is properly escaped';

$string = "This 'string' is just fine as it is";

$string = 'This  "string" is fine, also';

 

Well, I think you get the idea.

 

I got that concept but as far as I could tell each of my strings only had one set of quotes.  Anyway switching from single to "" quotes seemed to fix the problem of the page mostly being blank.  Now I am getting title as "TITLE" instead of the value stored IN TITLE.  I tried $TITLE but that produces not title at all...

post your calling code and the code of the page with the defines in it and i'll have a play and see why its not working. There is no real reason it shouldn't be. It sounds as if you are double quoting around the <?php echo "TITLE" ?> which will only produce TITLE. This shouldn't be quoted at all.

 

 

In the code you posted above, I don't see where the echo() statements are used to echo the constants. Where is the code that contains the <?php echo TITLE ?>, etc. ?

Ok here is my page now:

 

<?php

 

 

define(TITLE, "Health Basics | The Website Of Andrea Stevens, M.S., C.N.S., C.M.T.A. Clinical Nutritionist");

define(METATAGDESC, "Andrea Stevens is a clinical nutritionist specializing in consultations on digestive system dysfunction and children with neurological and developmental disorders as well as educational programs focusing on natural whole foods and wellness.  Health Basics is an international distributor of natural health products, vitamins and supplements.");

define(METAKEYWORDS, "metabolic typing, body ecology, body ecology diet, digestive problems, digestive disorders, food sensitivities, dysbiosis, autism, asperberger syndrome, aspergers syndrome, asperger's syndrome, asperger, aspergers, asperger's, ASD, spectrum disorder, GI problems, GI disorders, gastrointestinal problems, gastrointestinal disorders, whole foods nutritionist, natural nutritionist, functional nutritionist, functional healthcare, organic foods, organic, holistic healing, holistic healthcare, digestive system disorders, candidiasis, candida, candida related problems, yeast related problems, yeast overgrowth, infant feeding, infant feeding problems, failure to thrive, children eating problems, children neurological problems, neurological problems, eating problems, seizures, behavior problems, learning problems, learning disabilities, learning disability, attention deficit disorder, ADD, attention deficit disorder, attention deficit hyperactivity disorder, ADHD, hyperactivity, hyperactivity disorder, DAN Protocol, leaky gut, crohns, crohn's, crohns disease, crohn's disease");

 

?>

 

<h2>Philosophy & Focus</h2>

      <p>My primary goal is to assist clients in achieving the highest degree of health possible for themselves and their families. Drawing upon up-to-date scientific findings as well as forgotten but highly valuable knowledge - which includes old-fashioned methods of food preparation - I enjoy helping others to use natural ways to support their health and avoid illness and disease. Prescription medication, with its highly undesirable side effects, should not be the first or primary method of addressing ill health.</p>

      <p><br />

        The human body is wonderfully designed with countless mechanisms to stay healthy and balanced. If we can provide the body with all the natural raw materials (an abundance of nutrients, pure water, clean air, and love and intimacy among them) that it needs, as well as support the elimination of waste material and toxins, the body can heal many conditions and increase its levels of health, energy and vitality.</p>

<p><br />

       

          <div class="box">

         

          <center><b><i><p>Essential Nutrients in... Waste out!</p>

          <p>This is a model that all living organisms follow in order to thrive and flourish.</p></b></i></center>

         

               

         

          </div>

              <p><br />

          <p>Before turning to over-the-counter and prescription medications - which primarily suppress symptoms instead of address the underlying causes of dysfunction - understanding, and then supporting, the natural processes of the body will often result in a marked decrease or elimination of those symptoms. Symptoms are nature's way of calling our attention to problems in the body. Perhaps we are meant to listen to those signals and then correct the habits in our lifestyle that contribute to the underlying dysfunction (which then results in specific symptoms). These habits usually involve failing to provide the body with enough of the raw materials it needs, and hampering its detoxification, or waste removal, pathways.</p>

          <p><br />

          <p>The answer to our health problems doesn't lie in treating (suppressing) symptoms, but in addressing the causes - which are generally some combination of nutritional deficiencies and waste buildup within the body.</p>

          <p><br />

          <p>Two major concepts govern my approach. The first is that of biochemical individuality, which states that no two people are exactly alike and, therefore, no one dietary program is best for everyone... the Metabolic Typing philosophy addresses this. Secondly, I believe - as most physicians did prior to the mid 20th century - that overall health is directly dependent upon the health of the gastrointestinal or digestive tract... the Body Ecology approach addresses this.</p>

          <p><br />

          <p>I hold a firm belief in the inherent power, wisdom, and uniqueness in each of us. Eating natural, unaltered whole foods grown or raised in a healthy and socially responsible manner, along with proper digestive system-processing of those foods, are key to achieving optimal health, energy and vitality.</p>

          <p><br />

       

          <div class="box">

         

          <center<b><i><p>We need to Understand the <b>BASICS</b> of Body Functioning and the <B>BASICS</B> of Health-Supporting Food in order to Achieve BASIC Good Health. </p></b></i></center>

       

         

               

         

          </div>

         

              <p><br />

             

              <p>Specific conditions which can be successfully treated through Whole Food Nutrition and Optimal Digestive System Functioning include:</p>

              <p><br />

              <p>Overt Digestive Problems</p>

             

                    <ul>

            <li>Infant and Child Feeding Problems</li>

            <li>Reflux/GERD</li>

      <li>Food Sensitivities, Allergies, Intolerances</li>

            <li>Heartburn/Indigestion</li>

            <li>Bloating/Gas</li>

            <li>Constipation</li>

      <li>Diarrhea / Loose Bowel Movements</li>

            <li>Irritable Bowel Syndrome (IBS)</li>

              </ul>

              <p><br />

             

            <p>Systemic Problems Related to an Underlying Unhealthy Digestive System</p>

            <ul>

            <li>Candidiasis</li>

            <li>Autism Spectrum Disorder</li>

            <li>Attention Deficit Disorder (ADD), Attention Deficit Hypactivity Disorder (ADHD) and other Behavior and Learning Problems</li>

      <li>Epilepsy and Seizures</li>

            <li>Autoimmune Conditions like Rheumatoid Arthritis, Lupus, Multiple Sclerosis</li>

            <li>Chronic Fatigue</li>

            <li>Fibromyalgia</li>

            <li>"Mysterious Medical Maladies" - conditions unable to be successfully diagnosed or treated within the traditional healthcare system</li>

           

              </ul>

              <p><br />

              <p>Prevention of Health Problems and Disease</p>

              <ul>

              <li>Pregnancy Preparation</li>

                <li>Pregnancy</li>

                  <li>Graceful Aging</li>

                    <li>Optimal Levels of Energy, Vitality and Health</li>

                   

              </ul>

             

             

 

 

<!-- START Google Analytics -->

 

<script type="text/javascript">

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

</script>

<script type="text/javascript">

try {

var pageTracker = _gat._getTracker("UA-12299340-1");

pageTracker._setDomainName(".healthbasics.net");

pageTracker._trackPageview();

} catch(err) {}</script>

 

<!-- Google Analytics END -->

 

<!-- Start of StatCounter Code -->

<script type="text/javascript">

var sc_project=5441595;

var sc_invisible=1;

var sc_partition=54;

var sc_click_stat=1;

var sc_security="a84f73c6";

</script>

 

<script type="text/javascript"

src="http://www.statcounter.com/counter/counter_xhtml.js"></script><noscript><div

class="statcounter"><a title="web analytics"

class="statcounter" href="http://www.statcounter.com/"><img

class="statcounter"

src="http://c.statcounter.com/5441595/0/a84f73c6/1/"

alt="web analytics" /></a></div></noscript>

<!-- End of StatCounter Code -->

 

 

And my calling code:

 

<title><?php echo TITLE ?></title>

 

For whatever reason this is just making my title "TITLE"

 

Where is the echo statement? It isn't anywhere in the script above. It appears that the above is probably included by another script, in which case the TITLE constant wouldn't yet be defined when it is called.

Where is the echo statement? It isn't anywhere in the script above. It appears that the above is probably included by another script, in which case the TITLE constant wouldn't yet be defined when it is called.

 

THen I guess I don't understand what hte echo statement is or where it belongs.

 

What is the "echo statement" and exactly where do I need to put it?

 

I was under the impression that it goes in index.php and that the echo statement IS: <title><?php echo TITLE ?></title>

Where is the echo statement? It isn't anywhere in the script above. It appears that the above is probably included by another script, in which case the TITLE constant wouldn't yet be defined when it is called.

 

THen I guess I don't understand what hte echo statement is or where it belongs.

 

What is the "echo statement" and exactly where do I need to put it?

 

I was under the impression that it goes in index.php and that the echo statement IS: <title><?php echo TITLE ?></title>

 

The above seems ok. The calling code is just <?php echo TITLE; ?> or <?php echo METATAGDESC; ?> etc... The problem may be with where you are including the external php page into your index.php. Are you placing the <?php echo TITLE ?> before you include the page of html that is required? If so then that part of the page would of already been written before the php script can pick up on the fact TITLE should contain anything. For example:

 

<head>
<title><?php echo TITLE; ?></title>
</head>

include('relevantpage.php'); // page containing the define statements

 

the above won't work... as when the title is asked for, there is no define statement loaded. The following on the other hand would work:

 

include('relevantpage.php'); // page containing the define statements

<head>
<title><?php echo TITLE; ?></title>
</head>

 

It may just be that you are deciding what page it should be too late... move your page=whatever part and include such and such php file (with define statements) above the echo TITLE script.

 

 

Oh and off topic but your above code is missing the > from the center tag in the following:

 

<center<b><i><p>We need to Understand the <b>BASICS</b> of Body Functioning and the <B>BASICS</B> of Health-Supporting Food in order to Achieve BASIC Good Health. </p></b></i></center>

 

 

I hope my waffling helps?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.