Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Simple PHP syntax question


yacpro13

Recommended Posts

Hi all,

here's the piece of code (from the easy meta tags contrib)

 

$meta_title_tag = $category_name['categories_name'] . ' - ' . STORE_NAME;

 

I've added the

 . ' - ' . STORE_NAME

myself, but now I am wondering how to add a static piece of text before the category name?

 

I want to add an adjective that is valid for all categories. The code should go between the = and the $

 

Thanks

Link to comment
Share on other sites

I'm not sure that I understand your question. From a syntax point of view, you add a static string before the category name in the same way as you added two static strings after it. E.g.

$meta_title_tag = '>> ' . $category_name['categories_name'] . ' - ' . STORE_NAME;

However, if you want to add text, from an osCommerce point of view, you should add it to the language file with something like

define('META_TITLE_PREFIX', 'My title prefix');

and then change your title line as so

$meta_title_tag = META_TITLE_PREFIX . ' - ' . $category_name['categories_name'] . ' - ' . STORE_NAME;

Or maybe I'm misunderstanding your question?

Always back up before making changes.

Link to comment
Share on other sites

thanks; for some reason I thought there should have been 2 dots.

 

Anyway, mind if I asked another question?

 

$meta_keywords_tag = 

 

...How would I go about creating a dynamic list of all categories and all manufacturers?

Link to comment
Share on other sites

	$meta_keywords_tag = '';
  $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where language_id = '" . (int)$languages_id . "'");
while ($categories = tep_db_fetch_array($categories_query)) {
  $meta_keywords_tag .= $categories['categories_name'] . ', ';
}

or something like that. Manufacturers would be pretty much the same, although don't reset the tag to the empty string again.

Always back up before making changes.

Link to comment
Share on other sites

Your code works flawlessly. Great stuff.

 

I understand that the manufacturers would be the almost the same by itself, but I am not sure how to fetch both the categories (which you have done), then the manufacturers and assign it to meta_keywords_tag ?

Link to comment
Share on other sites

Does it help if I tell you that

	$meta_keywords_tag = '';
  $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where language_id = '" . (int)$languages_id . "'");
while ($categories = tep_db_fetch_array($categories_query)) {
  $meta_keywords_tag .= $categories['categories_name'] . ', ';
}
  $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where language_id = '" . (int)$languages_id . "'");
while ($categories = tep_db_fetch_array($categories_query)) {
  $meta_keywords_tag .= $categories['categories_name'] . ', ';
}

will display the categories twice in the keywords tag?

 

Go ahead and give it a try. If you post non-working code here, someone will help you with making it work.

Always back up before making changes.

Link to comment
Share on other sites

Here's what I have:

$meta_keywords_tag = '';
     $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where language_id = '" . (int)$languages_id . "'");
   while ($categories = tep_db_fetch_array($categories_query)) {
     $meta_keywords_tag .= $categories['categories_name'] . ', ';
   }
     $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS;
   while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
     $meta_keywords_tag .= $manufacturers['manufacturers_name'] . ', ';
   }

 

 

It reports an error and the second while loop.

Link to comment
Share on other sites

Try

	$meta_keywords_tag = '';
$categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where language_id = '" . (int)$languages_id . "'");
while ($categories = tep_db_fetch_array($categories_query)) {
  $meta_keywords_tag .= $categories['categories_name'] . ', ';
}
$manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS);
while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
  $meta_keywords_tag .= $manufacturers['manufacturers_name'] . ', ';
}

Anytime you see an error like Unexpected TWHILE, it usually means that there is missing punctuation. Is that the error that you had?

Always back up before making changes.

Link to comment
Share on other sites

All this for one bracket!....Well thanks you so much for your help. This code works very well. It will be useful when adding new categories and new manufacturers to have them automatically added to the meta keywords. Great stuff.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...