Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / How to make the Long Title limit char. long?

How to make the Long Title limit char. long?

Locked

Views: 2,940

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
20 Aug 2009, 1:42 PM
#1
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

How to make the Long Title limit char. long?

Hi all,

I am using 1.3.7 with a bought template from online ...

We all know the main home page have the "New Products of August"

It have the product title ....

The problems here, my products general long title, Over 50 to 100 words ...

I want to make like that .. for example ...

Halo 3 ODST Only on XBOX 360

I want it reformat like limit word to like that

Halo 3 ODST Only ...

Have the ... at the end .. and limit char word ...

I am not programming ... but I finded the code that using on my template

$products_name = '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a>';

How to reformat above code to make what I want to be?

Thank you very much and you time to help me.:frusty:

23 Aug 2009, 10:08 PM
#2
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: How to make the Long Title limit char. long?

You may be looking in the wrong place. Or you are if I understand correctly and you are trying to change the new products box in the center column.

You need to find new_products.php.

First make an override version of it if one does not exist already. So copy this file:

includes/modules/new_products.php

to this postition ( create folders if you need to )

includes/modules/yourtemplate/new_products.php.

Then you are going to edit this new file. Find the bit that reads:

  while (!$new_products->EOF) {
    $products_price = zen_get_products_display_price($new_products->fields['products_id']);
    if (!isset($productsInCategory[$new_products->fields['products_id']])) $productsInCategory[$new_products->fields['products_id']] = zen_get_generated_category_path_rev($new_products->fields['master_categories_id']);

    $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a><br />' . $products_price);

Then you are going to add two chunks of code (both in red):

  while (!$new_products->EOF) {
//niccol
$niccol=$new_products->fields['products_name'];
$niccol_array=explode(' ',$niccol);
if(count($niccol_array)>=4 ? $niccol_end='...' : $niccol_end='');
$niccol_new=$niccol_array[0].' '.$niccol_array[1].' '.$niccol_array[2].$niccol_end;
//niccol end
    $products_price = zen_get_products_display_price($new_products->fields['products_id']);
    if (!isset($productsInCategory[$new_products->fields['products_id']])) $productsInCategory[$new_products->fields['products_id']] = zen_get_generated_category_path_rev($new_products->fields['master_categories_id']);

    $list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsNew centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => (($new_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $new_products->fields['products_image'], $new_products->fields['products_name'], IMAGE_PRODUCT_NEW_WIDTH, IMAGE_PRODUCT_NEW_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . /*$new_products->fields['products_name'] .*//*niccol start*/$niccol_new./*niccol end*/ '</a><br />' . $products_price);

Probably it is easy to copy and paste from the forum into your file.

This will only display the first three words of the title. If you want to change that number it is easy to do in the first chunk of code.

24 Aug 2009, 6:37 AM
#3
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: How to make the Long Title limit char. long?

Nick,

Thank you. yes the file are what I want to change ...

But I am using override already, and the coding I post there is the template that using the override's coding ....

The template author make this code.

I just know that if I need control the output format...

Much change this coding....

Since I have other web site that have other template installed ... and I changed the result like what I want by using PHP's

substr, strlen, strip_tags

I give you the coding example for your refernece, that is I want to change the original template author coding like that one using substr, strlen, strip_tags but I an out of lucky ...

The coding is there:

$product_info_str .= (strlen($product_info->fields['products_description']) > 100) ? substr(strip_tags($product_info->fields['products_description']), 0, 100) . '…' : strip_tags($product_info->fields['products_description']);

:no:

24 Aug 2009, 7:21 AM
#4
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: How to make the Long Title limit char. long?

OK well thats fine.

Use the code that I posted wherever you want. The first bit of the code does the work:

$niccol=$new_products->fields['products_name'];
$niccol_array=explode(' ',$niccol);
if(count($niccol_array)>=4 ? $niccol_end='...' : $niccol_end='');
$niccol_new=$niccol_array[0].' '.$niccol_array[1].' '.$niccol_array[2].$niccol_end;

Line 1: Set variable $niccol to be the same as the products name

Line 2: turn the description into an array of individual words.

Line 3. If the array is smaller than 4 words do not use '...'

Line 4. Build a new variable that is the first three words of $niccol

These four lines act on any string that you set in the first line. So, what ever the string is the variable $niccol_new will be the first three words.

You can use it wherever you want in the file.

This is the code you are replacing?```
$products_name = '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a>';


|If that is right then this is what you want:

$products_name = '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $new_products->fields['products_name'] . '</a>';
$niccol=$new_products->fields['products_name']
$niccol_array=explode(' ',$niccol);
if(count($niccol_array)>=4 ? $niccol_end='...' : $niccol_end='');
$niccol_new=$niccol_array[0].' '.$niccol_array[1].' '.$niccol_array[2].$niccol_end;
$products_name_niccol= '<a href="' . zen_href_link(zen_get_info_page($new_products->fields['products_id']), 'cPath=' . $productsInCategory[$new_products->fields['products_id']] . '&products_id=' . $new_products->fields['products_id']) . '">' . $niccol_end. '</a>';
$products_name=$products_name_niccol;


I have not been able to test this code so check it before using it.
24 Aug 2009, 10:13 AM
#5
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: How to make the Long Title limit char. long?

Nick,

It not work ...

Or do I need give you my template for install on your shop to help for testing?

I can give my template that using for you.

Thank you very much.

24 Aug 2009, 10:30 AM
#6
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: How to make the Long Title limit char. long?

post your version of the template file (includes/modules/yourtemplate/new_products.php) as an attachment to the post. You will need to zip it first to attach it.

Also post a URL please.

25 Aug 2009, 7:33 AM
#7
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: How to make the Long Title limit char. long?

Hi Niccol,

Attachment file give to you....

If you need the full template, just ask me, I can PM you the download URL.

1000 x Thank you of your time and help me.

Best Regards,
Jimmy Chan

25 Aug 2009, 7:35 AM
#8
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: How to make the Long Title limit char. long?

Coding on line 85 and 196

Please note that 196 is the final output ..... base on my poor knowledge ....

Just know that 196 is using line 85 to format the output ...

25 Aug 2009, 8:37 AM
#9
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: How to make the Long Title limit char. long?

Thanks. I am in meetings all day today so it will be a while until I get a chance to really look at it. :smile:

25 Aug 2009, 10:38 AM
#10
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: How to make the Long Title limit char. long?

Niccol,

Never mind, I am very thank you of your kindly help.

Wish you all the best and have a nice day.

Jimmy Chan

27 Aug 2009, 8:20 AM
#11
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: How to make the Long Title limit char. long?

THis is what I think your file should look like. I have marked up the changes clearly. let me know how you get on.

28 Aug 2009, 5:57 AM
#12
explorer1979 avatar

explorer1979

Inactive

Join Date:
Jan 2007
Posts:
377
Plugin Contributions:
0

Re: How to make the Long Title limit char. long?

Niccol,

1000 x Thank you.

It work now. you help me a lot. :hug:

Jimmy