If this is your first visit, check our documentation. To post, register or login.
Forums / Customizing the Look of Your Shop / Templates, Stylesheets, Page Layout / set a character limit for product title to show a certain number of characters

set a character limit for product title to show a certain number of characters

Started by annav on 7 Jun 2013, 9:38 AM · Views: 1,702

Results 1 to 10 of 10
7 Jun 2013, 9:38 AM
#1
annav avatar

annav

Zen Follower

Join Date:
Jul 2008
Location:
Sydney, Australia
Posts:
171
Plugin Contributions:
0

Post #1 by annav

Hi,

I found this thread below which sort of answers my question, but the reply states that the line to edit is Line 97 on V1.5.1.

http://www.zen-cart.com/showthread.php?205920-How-to-set-a-character-limit-for-product-title-when-in-product-listing-mode

I'm using v1.5.0 and although it is not on line 97, the code is there but it's written in several places and I don't know which one to edit.

Can someone help.

Thanks.
Anna
https://www.toycrazy.com.au

9 Jun 2013, 6:02 AM
#2
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #2 by rodg

annav:

Hi,

I found this thread below which sort of answers my question, but the reply states that the line to edit is Line 97 on V1.5.1.

http://www.zen-cart.com/showthread.php?205920-How-to-set-a-character-limit-for-product-title-when-in-product-listing-mode

I'm using v1.5.0 and although it is not on line 97, the code is there but it's written in several places and I don't know which one to edit.

Can someone help.

Thanks.
Anna
www.toycrazy.com.au

I've no idea what your search query is/was, but I've just used the Developer Toolkit and performed a search for
$lc_text = '<h3 class="

This produced one result, which is on line#96 of /includes/modules/product_listing.php (ZenCart V1.5.0)

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

9 Jun 2013, 6:46 AM
#3
annav avatar

annav

Zen Follower

Join Date:
Jul 2008
Location:
Sydney, Australia
Posts:
171
Plugin Contributions:
0

Post #3 by annav

Thanks Rod.

I does only come up once in /includes/modules/product_listing.php.

I thought that the changes had to be made to the one in the template file, in my case, includes/modules/piccadilly_posh/product_listing.php where it comes up twice on Lines 139 and 141 as follows (they both look identical to me):

Line #139 : $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;

Line #141 : $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';

I made the changes to the one that you mentioned, putting in my own character limit but it didn't work.

Does it need to be changed in the template file as well, and if so which one?

Thanks
Anna
https://www.toycrazy.com.au

PS Hope you're having a great long weekend!

9 Jun 2013, 9:07 AM
#4
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #4 by rodg

annav:

I does only come up once in /includes/modules/product_listing.php.

I thought that the changes had to be made to the one in the template file, in my case, includes/modules/piccadilly_posh/product_listing.php

You thought correctly. I neglected to take the template override file into account.

annav:

where it comes up twice on Lines 139 and 141 as follows (they both look identical to me):

They look identical to me too.

annav:

I made the changes to the one that you mentioned, putting in my own character limit but it didn't work.
Does it need to be changed in the template file as well, and if so which one?

Apologies. I led you a little astray here. Your template file will take precedence over the original file (which ideally shouldn't be modified anyway). Although currently harmless, it'll pay to revert /includes/modules/product_listing.php back to the original zencart code, as we'll often suggest reverting to original code when debugging, and if their is anything amiss with the changes you made, they won't appear until this time, which will then compound the original problem

As for the changes to your template file. I'd suggest you make the same change in both places.

Without seeing the full code I/we can't comment what/where/when each or either of these lines is actually invoked. If you change one but not the other, you'll have the full title in some instances and the truncated ones in others.

Depending on these conditions this could be used to your advantage.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

9 Jun 2013, 9:53 AM
#5
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #5 by rodg

Update:

Not being happy with two long lines of identical code, I thought I'd look a little deeper and have d/loaded the piccadilly_p template file(s).

The product_listing.php file contained is based on ZenCart V1.3.6 code (not that there anything particularly wrong with that), but it appears in this case it was either based on a bad piece of code, or the modifications themselves are bad. Not in a harmful way, because the code as it stands is useless/pointless.

In simple terms it reads like: "If this variable is set, do this thing. If it isn't set, do the exact same thing with this other line of code".

I've noted in the latest/current zencart release this superfluous code has been removed, and for all I know, it was fixed/removed way back in V1.3.7. The template file(s) haven't kept up with the changes.

As I say though, although this is bad code that has long been fixed, it isn't harmful in any way. It just means you will need to edit both lines (or remove the if/else that determines which line is used at any given time).

Having said that, and I've no wish to worry you, but using template files based on old ZenCart code should be treated with a little caution. In this case there's nothing to worry about. What does concern me is the possibility of the older code still being vulnerable to current day exploits.

Cheers
Rod

ps. Although I've not 'vetted' the code for any security type issues, nothing stood out to ring any alarm bells either.

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

9 Jun 2013, 10:52 AM
#6
annav avatar

annav

Zen Follower

Join Date:
Jul 2008
Location:
Sydney, Australia
Posts:
171
Plugin Contributions:
0

Post #6 by annav

I have edited both lines but it still didn't make any difference so then just did one and not the other but still the same.

I think i'll contact the designer of template and see what she says.

9 Jun 2013, 2:31 PM
#7
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #7 by rodg

annav:

I have edited both lines but it still didn't make any difference so then just did one and not the other but still the same.

I still reckon you should do both.

Also, don't forget to clear your browser cache before checking for changes, lest ye be seeing old data.

Also, the example code is truncating the field at 50 characters, so if your titles are shorter than that you won't see any difference anyway.

My 'tip' when making a change like this, is to use 'extreme' values. For example, rather than limiting to 50 characters try setting it to 5 or 10 characters instead. This will/should make the effects of the change(s) very obvious. You can then tweak the value to suit your needs once you have confirmed it is actually doing what it is supposed to be doing (or not).

annav:

I think i'll contact the designer of template and see what she says.

The designer is always the most authoritative source for specific/accurate answers, but if the tips I've given are of any help you won't need to wait for their response.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

10 Jun 2013, 9:12 AM
#8
annav avatar

annav

Zen Follower

Join Date:
Jul 2008
Location:
Sydney, Australia
Posts:
171
Plugin Contributions:
0

Post #8 by annav

Yes, I cleared the browser cache etc and experimented with different character limits (went down to five) but still no changes.

I have contacted the designer, so just waiting now to hear back from her.

Thanks for all your help.

Anna

10 Jun 2013, 9:39 AM
#9
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Post #9 by rodg

annav:

Yes, I cleared the browser cache etc and experimented with different character limits (went down to five) but still no changes.

This always has me somewhat concerned. It is near impossible to make code changes without some effect. If I'm not seeing the effect(s) in places where I'm expecting to see them, it means I'm either editing the wrong file, or the wrong place in the right file.
In either case, I ensure I revert any changes made back to how it was before making any other changes. You must do the same.

annav:

I think i'll contact the designer of template and see what she says

If you've nothing better to do whilst waiting a reply, you could try adding a line of code immediately after the line(s) that you edited, that reads:

echo "Here <line number>" ; exit ;

If you still see 'no change' then you really are editing the wrong place or wrong file for what you are trying to achieve.
On the other hand, if/when the page being displayed abruptly aborts with the 'Here <line number' text you'll know you are editing the right place/file (assumedly) and your edits to the previous lines will come into play. If you still don't see the effects of the edits, then you are looking in the wrong place, which effectively means the example code changes supplied are/were for a different thing than the changes that you are seeking to make. If this is the case, it may be wise to start a new thread and explain exactly what it is that you are trying to achieve and where you expect the shortened 'product_title' to appear on-screen.

Cheers
Rod

NOTE: We are sorry that Rod is no longer with us.
We are grateful for all his contributions to the Zen Cart community.

Ozpost - The Ultimate Shipping module for Australian Merchants. Click these links for its Homepage, or Download from Zen-Cart.com.

10 Jun 2013, 1:38 PM
#10
annav avatar

annav

Zen Follower

Join Date:
Jul 2008
Location:
Sydney, Australia
Posts:
171
Plugin Contributions:
0

Post #10 by annav

OK, so I have worked out what happened.

There wasn't actually anything wrong with the code, it was working perfectly :blush:

I was concentrating on viewing and refreshing the home page looking for changes when the changes were in fact made on the actual category pages.

But what I don't understand is, why didn't these changes work on the home page?