Limiting Characters In Title
#1
Posted 13 September 2011 - 09:38 AM
Hopefully someone can help with my initial enquiry.
I am wanting to limit the amount of characters in the title for the video's and then add ... to the end.
An explanation or code-snippet would be much appreciated.
Regards
Sam
#2
Posted 13 September 2011 - 09:41 PM
You should be able to do this with a TubePress theme. In your theme's gallery.tpl.php, find the area where the title is displayed. In the default theme, it's around line 44...
<?php echo htmlspecialchars($video->getTitle(), ENT_QUOTES, "UTF-8"); ?>Simply change this to something like this:
<?php$title = $video->getTitle();$limit = 25;$title = strlen($title > $limit) ? substr($title, 0, 25) . '...' : $title;echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8');?>Make sense? Let me know if you need help at any step along the way.
#3
Posted 25 September 2011 - 10:18 AM
Hi Sam,
You should be able to do this with a TubePress theme. In your theme's gallery.tpl.php, find the area where the title is displayed. In the default theme, it's around line 44...<?php echo htmlspecialchars($video->getTitle(), ENT_QUOTES, "UTF-8"); ?>Simply change this to something like this:<?php$title = $video->getTitle();$limit = 25;$title = strlen($title > $limit) ? substr($title, 0, 25) . '...' : $title;echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8');?>Make sense? Let me know if you need help at any step along the way.
I was looking for exactly a way to do this, but it doesn't seem to be working for me anyway. Nothing happens with the title after changing this in the gallery template. Same title with the same amount of characters come out. Am I doing something wrong?
/oscar, sweden
#4
Posted 19 November 2011 - 09:29 PM
$title = $video->getTitle();
$limit = 25;
$title = (strlen($title) > $limit) ? substr($title, 0, 25) . '...' : $title /* <-- CORRECTION ON THIS LINE */;
echo htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
?>
#5
Posted 16 June 2015 - 07:37 AM
Hi there – I have the opposite request. I would like to use the YouTube Clone theme but INCREASE the title limit – can you please help?
#6
Posted 17 June 2015 - 02:48 AM
whysquare,
you would make the same modifications but change:
$limit = 25;$title = strlen($title > $limit)
to
$limit = 5;$title = strlen($title < $limit)
Want a faster, more personalized support experience? Open a ticket with us! We will be gradually phasing out forum-based support in favor of a proper ticketing system. Please help us help you!