Author Topic: Shorten (cut-down) image name length.  (Read 14710 times)

0 Members and 1 Guest are viewing this topic.

Offline M@2T

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • http://4images.aliciakeysfan.com
Shorten (cut-down) image name length.
« on: October 26, 2005, 10:51:47 PM »
Hey there,

Im wondering if someone can help me with this.

I currently have a very large image gallery, a lot of the images have names which are long, too long.  When they show up under the thumbnails anywhere, even on random image for eg, as the names are so long, it pushes the template out of line, very streched :/.

Anyone know of a why, to when the image name is too long, for eg, over 12 char's to limit at this value?

Many Thanks for your help everyone,
Cheers,
Matt

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Shorten (cut-down) image name length.
« Reply #1 on: October 27, 2005, 12:22:26 AM »
Here are two sollutions:
1) cut the name to NN number of letters
2) insert <wbr> tag every NN letters, which will "break" words if they dont fit in the table (its not a HTML standart, might not work properly in some browsers)

in includes/functions.php find:
Code: [Select]
    "image_name" => $image_row['image_name'],
for first method Insert below:
Code: [Select]
    "image_name_short" => (strlen($image_row['image_name']) > 12) ? substr($image_row['image_name'], 0, 12)."..." : $image_row['image_name'],For second method insert below:
Code: [Select]
    "image_name_short" => (strlen($image_row['image_name']) > 12) ? chunk_split($image_row['image_name'], 12, "<wbr>") : $image_row['image_name'],
Now in thumbnail_bit.html template you can use {image_name_short} tag
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline ruudvroon

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • AFTERTHEPARTY.NL
Re: Shorten (cut-down) image name length.
« Reply #2 on: October 27, 2005, 05:00:35 PM »
v@no, is it possible to cut the name to 12 letters in the {comment_image_name} which you use in: [MOD] Last comments v1

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Shorten (cut-down) image name length.
« Reply #3 on: October 28, 2005, 12:15:18 AM »
In Step 1 above
Code: [Select]
  $text = $row['comment_text']; add this:
Code: [Select]
  $row['image_name'] = (strlen($row['image_name']) > 12) ? substr($row['image_name'], 0, 12)."..." : $row['image_name'];Or this:
Code: [Select]
  $row['image_name'] = (strlen($row['image_name']) > 12) ? chunk_split($row['image_name'], 12, "<wbr>") : $row['image_name'];
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #4 on: February 16, 2006, 11:14:39 PM »
Is there a way to do this with subcats too?
The only thing I could find was this
Code: [Select]
"sub_cats" => get_subcategories($category_id),

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #5 on: February 16, 2006, 11:29:46 PM »
If you're looking to customize the get_subcategories function, you'd need to do so from includes/functions.php file.

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #6 on: February 17, 2006, 12:52:12 AM »
If you're looking to customize the get_subcategories function, you'd need to do so from includes/functions.php file.

I tried looking there. But could not really figure out how to do it :/

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #7 on: February 17, 2006, 01:13:49 AM »
Ok, the following has not been tested but returns no error. Let's try this.

First, make a backup of your includes/functions.php file.

Then, find :

Quote

$sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".$cat_cache[$subcat_id]['cat_name']."</a>";


replace with :

Code: [Select]

$sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".(strlen($cat_cache[$subcat_id]['cat_name']) > 12) ? substr($cat_cache[$subcat_id]['cat_name'], 0, 12)."..." : $cat_cache[$subcat_id]['cat_name']."</a>";


Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: Shorten (cut-down) image name length.
« Reply #8 on: February 17, 2006, 01:48:56 AM »
Quote from: V@no

in includes/functions.php find:
Code: [Select]
    "image_name" => $image_row['image_name'],

I don´t have this. I have this

Code: [Select]
"image_name" => multilang($image_row['image_name']),
what must i change in this line

Code: [Select]
"image_name_short" => (strlen($image_row['image_name']) > 12) ? substr($image_row['image_name'], 0, 12)."..." : $image_row['image_name'],
Thanks for helping...
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Shorten (cut-down) image name length.
« Reply #9 on: February 17, 2006, 01:52:10 AM »
Code: [Select]
"image_name_short" => (strlen(multilang($image_row['image_name'])) > 12) ? substr(multilang($image_row['image_name']), 0, 12)."..." : multilang($image_row['image_name']),
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #10 on: February 17, 2006, 04:49:36 PM »
Ok, the following has not been tested but returns no error. Let's try this.

First, make a backup of your includes/functions.php file.

Then, find :

Quote

$sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".$cat_cache[$subcat_id]['cat_name']."</a>";


replace with :

Code: [Select]

$sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".(strlen($cat_cache[$subcat_id]['cat_name']) > 12) ? substr($cat_cache[$subcat_id]['cat_name'], 0, 12)."..." : $cat_cache[$subcat_id]['cat_name']."</a>";


It's not showing up as a link and the class is nether applyed

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #11 on: February 17, 2006, 05:45:28 PM »
Ok. I see what you mean.

In includes/functions.php file,

find this block :

Quote

}
    else {
      $random_cat_image_file = get_random_image($category_id, 0, 1);
    }

    $site_template->register_vars(array(
      "cat_id" => $category_id,


right below, you will see :

Quote

"cat_name" => $cat_cache[$category_id]['cat_name'],


replace with :

Code: [Select]

"cat_name" => (strlen($cat_cache[$category_id]['cat_name']) > 12) ? substr($cat_cache[$category_id]['cat_name'], 0, 12)."..." : $cat_cache[$category_id]['cat_name'],


This should do it. ;)

(Note: This is a continuation from the above, not a completely fresh new step). ;)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #12 on: February 17, 2006, 06:31:59 PM »
When I use the last code it changes the category text and has no effect on subcats.
And I only need this for subcategoryes

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: Shorten (cut-down) image name length.
« Reply #13 on: February 17, 2006, 07:04:03 PM »
Quote

When I use the last code it changes the category text and has no effect on subcats.


This is what I find odd actually. If you go to your index page, you should see your subcats title with a max number of 12 with "..." (if text is longer than 12 - of course). Are you talking about the inside of the subcats page where you do not see these readings ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Shorten (cut-down) image name length.
« Reply #14 on: February 18, 2006, 12:40:46 AM »
Are you talking about the inside of the subcats page where you do not see these readings ?
They are talking about the list of subcategories under parent category name.

@BartAfterDark:
in includes/functions.php find:
Code: [Select]
      $sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".$cat_cache[$subcat_id]['cat_name']."</a>";
Replace with:
Code: [Select]
      $sub_cat_list .= "<a href=\"".$sub_url."\" class=\"subcat\">".((strlen($cat_cache[$subcat_id]['cat_name']) > 12) ? substr($cat_cache[$subcat_id]['cat_name'], 0, 12)."..." : $cat_cache[$subcat_id]['cat_name'])."</a>";
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)