You are here:  » Atoz.php Display Mod

Support Forum



Atoz.php Display Mod

Submitted by dbfcs on Tue, 2008-03-11 11:16 in

In some product feeds, the data is less than perfect. Sometimes long category names can crop up. So instead of the nice standard "MP3 Players", some merchants like to use "Consumer Electronics > Audio > MP3 Players". This can sometimes mess with your layout and just look plain ugly.

Around line 19 in atoz.php, change:

<?php
print "<p><a href='".$item["href"]."'>".$item["name"]."</a></p>";
?>

to:

<?php
if (strlen($item["name"])>50)
{
print 
"<p><a href='".$item["href"]."' title='".ucwords(strtolower($item["name"]))."'>".ucwords(strtolower(substr($item["name"],0,50)))."...</a></p>";
} else {
print 
"<p><a href='".$item["href"]."' title='".ucwords(strtolower($item["name"]))."'>".ucwords(strtolower($item["name"]))."</a></p>";
}
?>

The changes made here are:

  1. A title tag is added to the hyperlink so that when the user hovers over it, it displays some text. This helps with accessibility.
  2. All output is formatted the same. Everything Is In Title Case (Not lower or UPPER case).
  3. If the text to be displayed is longer than 50 characters, it is shrunk to 50 characters and "..." is displayed after it. If it is less than 50 characters in the first place, it is displayed as is.

This may help someone somewhere!

Submitted by atman on Thu, 2008-10-16 06:10

dbfcs,

is it possible to crop the category length 50 chacacters BUT if the 50th character falls in the middle of a word, the complete word would be displayed instead of cropping it in the middle. is this even posible?

thanks for sharing!, i am using your mod.

Submitted by support on Thu, 2008-10-16 07:49

Hi atman,

I can reply for Dave (hope he doesn't mind...!)

That's easy to do, instead of just using 50 on it's own, you can use the output from strpos() looking for a SPACE character with an offset of 50. Simply replace:

ucwords(strtolower(substr($item["name"],0,50)))

with:

ucwords(strtolower(substr($item["name"],0,strpos($item["name"]," ",50))))

Cheers,
David.