Post by dashik » Wed Nov 11, 2009 2:52 pm

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!

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by dashik » Wed Nov 11, 2009 8:11 pm

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

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Thu Nov 12, 2009 12:45 am

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; ?>

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by i2Paq » Thu Nov 12, 2009 2:41 am

What will this do excactly?

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by Qphoria » Thu Nov 12, 2009 4:12 am

I guess he wants to use the meta_description as another description field to display on the product page

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Fri Nov 13, 2009 9:15 pm

Thank you! That's exactly what i needed.

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by dashik » Fri Nov 13, 2009 9:23 pm

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?

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by dashik » Sat Nov 14, 2009 3:22 am

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.

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sat Nov 14, 2009 3:58 am

you mean you want hte product meta info to show up on the category page?

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sat Nov 14, 2009 5:13 am

^ yes, exactly. under each product listing.

For example...imagine:

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

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sat Nov 14, 2009 5:37 am

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 } ?>

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sat Nov 14, 2009 5:46 am

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!

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by dashik » Sun Nov 15, 2009 3:20 am

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!

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sun Nov 15, 2009 4:44 am

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).

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sun Nov 15, 2009 5:14 am

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.

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by Qphoria » Sun Nov 15, 2009 8:40 am

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'];
?>

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dashik » Sun Nov 15, 2009 10:34 pm

Anyone know how i can call the product_id of each listing in the category.tpl template file?

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by moggiex » Sun Nov 15, 2009 10:48 pm

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

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by dashik » Sun Nov 15, 2009 11:05 pm

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! :)

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by dashik » Sun Nov 15, 2009 11:09 pm

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

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm
Who is online

Users browsing this forum: No registered users and 35 guests