Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Code needed to change page title


mdtaylorlrim

Recommended Posts

Is there any way to make the page title change on the product_info.php? Dynamically, that is.

 

The product information is not retrieved from the db until after the page heading is rendered so I would have to make a serious change to the code in order to simply use the product description variable, which is the desired result.

 

So, anyone know any php or jscript code that will change the page title from within the body of the page? I am wanting the product description (or any other selected field) to be the page title.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

The best way to do it is to install one of the meta tags addons. I recommend Header Tags SEO (see My Addons) but there are many more.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Thanks for the fast reply, Jack. But after thinking over it during dinner and looking at the code again I realize that approach will not work. I will need to have the title rendered at the onset, for technical reasons.

 

So, here is my thinking....

 

Take all of the http header code from "<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">" and ending with "<!-- header //-->" and put it into a function.

 

Then, within the first conditional where it traps a 'no product selected' force in a variable with a 'No Product Selected' as the value, and call the function passing the variable.

 

Then, within the product listing, call the function once the product description has been retrieved.

 

I realize it is repetition, but it is the cleanest way of doing it, I believe.

 

 

So, anyone have a better solution or would someone like to provide the code for that. It would save me from having to set up a development store to do it, and someone else that is far better then me could likely do it in about 10 minutes as opposed to the hour+ it would take me with trial and lots of errors...

 

My biggest hurdle would be how does it affect the jscript function in the header?

 

Would your add-on accomplish this Jack?

 

 

Thanks

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

The use of the phase "page title" is a little ambigous. The page title typically refers to the title in the web browser for a particular page. The heading on the page, which is sounds like what you might mean, is called the page heading. I assumed you meant page title, which is what I answered since the page heading has always been dynamically handled in oscommerce. If you mean the page heading and it is not changing with each product, then my guess is that you are using a template that has replaced that code. If that is the case, you will need to add it back in. If you did mean the web browser title though, my first answer is correct. If you can provide a link to your product page, it might make finding an answer easier.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

The use of the phase "page title" is a little ambigous. The page title typically refers to the title in the web browser for a particular page. The heading on the page, which is sounds like what you might mean, is called the page heading. I assumed you meant page title, which is what I answered since the page heading has always been dynamically handled in oscommerce. If you mean the page heading and it is not changing with each product, then my guess is that you are using a template that has replaced that code. If that is the case, you will need to add it back in. If you did mean the web browser title though, my first answer is correct. If you can provide a link to your product page, it might make finding an answer easier.

No, I mean the page title in the html headers. i.e.

 

<html>

<head>

<title>This Title</title>

</head>

<body....

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

This is basically what I am after.

 

<title><?php pd.products_description; ?></title>

 

However this does not work, it renders the title blank.

 

and this...

 

 

<title><?php echo pd.products_description; ?></title>

 

literally put 'pdproducts_description' in the title. Notice the dropped period?

 

 

Nor does...

<title><?php echo pd\.products_description; ?></title>

 

 

Nor does...

<title><?php $product_info['products_name']; ?></title>

 

So what am I missing here?

 

 

 

Edited to add... However this did...

 

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

 

 

Instead of using functions I just copied all of the code twice into the if{} container making sure that it is after the db retrieval. Just had to get the variable right. Now, the browser displays the product name in the title bar of the browser. Meets my requirements now. Just need to be sure and keep the back up file for an extended time while its fully tested.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

And for the benefit of others the result is this:

 

Look up at the browser title bar where it reads "Code needed to change page title - osCommerce Community Support - [browser name]

 

Before it has always read "ABC Video Sales - [browser name]" on each and every page, regardless the content.

 

Now, mine reads:

 

"The War Wagon - John Wayne from ABC Video Sales - [browser name]" on the product info pages, and back to ABC Video Sales on all the others.

 

 

There really is a real good reason I wanted to do this...

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Now I really want to do this to the index.php file as well. Still looking for someone willing to tackle this one.

 

As I see it there are three cases, or if{} containers on the index page. One for clicking on a category, one for clicking on a manufacturer, and one default. I want the default to read the store name, as is the case for new installs. If you click on a category link I want the Title to read "Western DVD's by [store name]" and when clicking on Manufacturer it should read "Warner Bros Videos by [store name]" where, "Western DVD's" is a category and "Warner Bros" is a manufacturer.

 

 

This one will be a bit more complicated. I will consider paying someone to do this!

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

You're putting in a lot of time to gain something that is very minor when compared to the contributions I mentioned. You can spend your time re-inventing the wheel or take advantage of all of the work others have done over the years. For example, you added the code to add the title to a page. What about the meta description tag? How will you edit that? On the index page, what about adding text for the categories description that is keyed to the title. I could go on but I think you get the point. Trust me, you will be much happier after installing Header Tags SEO.

 

As for why the products description wouldn't work for the title, it was probably due to html in the description. But it wouldn't matter if it worked anyway since the search engines will strip out much of it.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

You're putting in a lot of time to gain something that is very minor when compared to the contributions I mentioned. You can spend your time re-inventing the wheel or take advantage of all of the work others have done over the years. For example, you added the code to add the title to a page. What about the meta description tag? How will you edit that? On the index page, what about adding text for the categories description that is keyed to the title. I could go on but I think you get the point. Trust me, you will be much happier after installing Header Tags SEO.

 

As for why the products description wouldn't work for the title, it was probably due to html in the description. But it wouldn't matter if it worked anyway since the search engines will strip out much of it.

Ok, I finally got a chance to look through your contrib and it of course does just what i want. A little more work that I want to put into it, but the return will be great. Want a contract job installing it? Send me a PM if you would.

Community Bootstrap Edition, Edge

 

Avoid the most asked question. See How to Secure My Site and How do I...?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...