Page 1 of 2

How can I display Meta Description on Product page?

Posted: Wed Nov 11, 2009 2:52 pm
by dashik
I'm not looking to add anything in the <head> portion...but just in the main body of the product.tpl file located at catalog/view/theme/default/template/product/product.tpl

I've tried all sorts of different things and I still can't figure this one out. I'm trying to display the contents of the meta_description field somewhere on the page and not just in the <head> -- how can I do this?

Thanks!

Re: How can I display Meta Description on Product page?

Posted: Wed Nov 11, 2009 8:11 pm
by dashik
I've given up trying to call the meta description and am now trying to query the db directly to return the meta where product_id equals the current product.

Any help on this would be greatly appreciated ;D

Re: How can I display Meta Description on Product page?

Posted: Thu Nov 12, 2009 12:45 am
by Qphoria
1. EDIT: catalog/controller/product/product.php

2. FIND:

Code: Select all

$this->document->description = $product_info['meta_description'];
3. AFTER, ADD:

Code: Select all

$this->data['meta_description'] = $product_info['meta_description'];
4. EDIT: catalog/view/theme/YOURTHEME/template/product/product.tpl

5. PASTE THIS WHERE YOU WANT IT:

Code: Select all

<?php echo $meta_description; ?>

Re: How can I display Meta Description on Product page?

Posted: Thu Nov 12, 2009 2:41 am
by i2Paq
What will this do excactly?

Re: How can I display Meta Description on Product page?

Posted: Thu Nov 12, 2009 4:12 am
by Qphoria
I guess he wants to use the meta_description as another description field to display on the product page

Re: How can I display Meta Description on Product page?

Posted: Fri Nov 13, 2009 9:15 pm
by dashik
Thank you! That's exactly what i needed.

Re: How can I display Meta Description on Product page?

Posted: Fri Nov 13, 2009 9:23 pm
by dashik
Q, what if I want to do the same thing on the category.tpl page?

What exactly do i need to insert into the category controller?

I tried finding this:

Code: Select all

$this->document->description = $category_info['meta_description'];
And adding this AFTER:

Code: Select all

$this->data['meta_description'] = $category_info['meta_description'];
And tried calling it with <?php echo $meta_description; ?> in the category.tpl template....but no luck.

Any ideas?

Re: How can I display Meta Description on Product page?

Posted: Sat Nov 14, 2009 3:22 am
by dashik
Oops, i just realized i wrote $category_info up there....what I meant to say is that i want that same product meta_description that Q helped me display to show up next to each product in the category view...and NOT the category's meta description.

Hope that makes sense.

Re: How can I display Meta Description on Product page?

Posted: Sat Nov 14, 2009 3:58 am
by Qphoria
you mean you want hte product meta info to show up on the category page?

Re: How can I display Meta Description on Product page?

Posted: Sat Nov 14, 2009 5:13 am
by dashik
^ yes, exactly. under each product listing.

For example...imagine:

[thumbnail]
[price]
[model]
[meta_description]

Re: How can I display Meta Description on Product page?

Posted: Sat Nov 14, 2009 5:37 am
by Qphoria
1. EDIT: catalog/controller/product/category.php

2. FIND:

Code: Select all

'model'   => $result['model'],
3. AFTER, ADD:

Code: Select all

'meta_description'   => $result['meta_description'],
4. EDIT: catalog/view/....../product/category.tpl

5. FIND:

Code: Select all

<?php if ($products[$j]['rating']) { ?>
        <img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
<?php } ?>
6. AFTER, ADD:

Code: Select all

<?php if ($products[$j]['meta_description']) { ?>
        <?php echo $products[$j]['meta_description']; ?>"
<?php } ?>

Re: How can I display Meta Description on Product page?

Posted: Sat Nov 14, 2009 5:46 am
by dashik
You, sir, are a life saver!

I wish i had money to donate but I have at least purchased like 3 of your modules so far (it was for the FishSmith site a couple of months ago if you recall). :)

Thanks for all the great work!

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 3:20 am
by dashik
Any idea how I can do the same for the meta keyword field?

I tried doing it with the exact directions above but it appears that this field might behave a bit differently and it doesn't show up on either the product or category pages.

Thanks!

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 4:44 am
by Qphoria
There is no meta keyword field. The keyword is for SEO urls. Meta keywords have been deemed useless for the past 2 years (google some info about it).

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 5:14 am
by dashik
Qphoria wrote:There is no meta keyword field. The keyword is for SEO urls. Meta keywords have been deemed useless for the past 2 years (google some info about it).
I understand but I'm just trying to re-use this field for another purpose like I did with the meta description product field.

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 8:40 am
by Qphoria
Try this in the product.tpl:

Code: Select all

<?php
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE query = 'product_id=" . (int)$product_id . "'");

echo $query->row['keyword'];
?>

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 10:34 pm
by dashik
Anyone know how i can call the product_id of each listing in the category.tpl template file?

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 10:48 pm
by moggiex
dashik wrote:Anyone know how i can call the product_id of each listing in the category.tpl template file?
Yes.

/catalog/controller/product/product.php

About line 143, you'll see something like this:

Code: Select all

$this->data['products'][] = array(
            			'name'    => $result['name'],
            			'rating'  => $rating,
						'stars'   => sprintf($this->language->get('text_stars'), $rating),
						'thumb'   => image_resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
            			'price'   => $price,
						'special' => $special,
						'page_url'	=> $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id'])),
						'href'    	=> $this->model_tool_seo_url->rewrite($this->url->http('product/product&path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']))
          			);
Replace with this:

Code: Select all

$this->data['products'][] = array(
            			'name'    => $result['name'],
						'model'   => $result['model'],
						'sku'   => $result['sku'],
						'id'	=> $result['product_id'],
            			'rating'  => $rating,
						'stars'   => sprintf($this->language->get('text_stars'), $rating),
						'thumb'   => image_resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
            			'price'   => $price,
						'special' => $special,
						'page_url'	=> $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id'])),
						'href'    	=> $this->model_tool_seo_url->rewrite($this->url->http('product/product&path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']))
          			);
This has now added 3 new parts to the product array returned:

Code: Select all

<?php echo $products[$j]['sku']; ?>
<?php echo $products[$j]['model']; ?>
<?php echo $products[$j]['id']; ?>
That can be used in:
catalog/view/theme/default/template/product/category.tpl

In the section that starts off like:

Code: Select all

<?php for ($i = 0; $i < sizeof($products); $i = $i + 2) { ?>
      <tr>
        <?php for ($j = $i; $j < ($i + 4); $j++) { ?>
        <td width="25%"><?php if (isset($products[$j])) { ?>
As you can see I ahve already been in here as model and sku were very oddly.. missing.

Matt

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 11:05 pm
by dashik
moggiex -- for some reason, that's not working for me.

this is what my product array looked like before:

Code: Select all

$this->data['products'][] = array(
            		'name'    => $result['name'],
					'model'   => $result['model'],
            		'rating'  => $rating,
					'stars'   => sprintf($this->language->get('text_stars'), $rating),
					'thumb'   => HelperImage::resize($image, $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),
            		'price'   => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
					'special' => $special,
					'href'    => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id']))
          		);
And after:

Code: Select all

$this->data['products'][] = array(
            		'name'    => $result['name'],
					'model'   => $result['model'],
					'id'   => $result['product_id'],
            		'rating'  => $rating,
					'stars'   => sprintf($this->language->get('text_stars'), $rating),
					'thumb'   => HelperImage::resize($image, $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height')),
            		'price'   => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
					'special' => $special,
					'href'    => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id']))
          		);
But category.tpl still won't call the product_id using

Code: Select all

<?php echo $products[$j]['id']; ?>
Keep in mind I am running 1.3.0 -- is there anything else I need to be doing?

Thanks! :)

Re: How can I display Meta Description on Product page?

Posted: Sun Nov 15, 2009 11:09 pm
by dashik
Ok i figured it out! The problem was that the changes needed to be made to the category.php controller, not product.php

Everything looks good now, thanks! ;D