By minesota on
I will like to limit long node titles to first 'n' characters in a side block ( which is narrow ) for example in 'recent blog posts' block
else if ($op == 'view') {
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), 0, 5);
if (db_num_rows($result)) {
$block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'blog', array('title' => t('Read the latest blog entries.'))) .'</div>';
$block['subject'] = t('Recent blog posts');
return $block;
For example, in the above how do I manipulate node_title_list with something like substr() to truncate long or very long titles?
Regards
Comments
Here's a snippet of code I
Here's a snippet of code I used once in a Views template, to shorten a node title... maybe it will help:
-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]
Hello, thanks a lot. Any
Hello, thanks a lot.
Any little help on how I can merge this into
node_title_list?If you want to change in
If you want to change in directly node.module then there is
where you can change the length of node title like
But better way is make your own block or you can also chage the theme function of
theme_item_list.Regards,
Vijay
Thanks,
Vijay Thummar
a very useful piece of code
Hello and regards
Thanks a LOT. That is a very useful piece of code.
[ There is one problem I am facing, with titles in unicode characters
substr($node->title, 0, 50is making certain titles just blank. Yet to figure out why this is happening. For example, withsubstr($node->title, 0, 40the truncated title is there, withsubstr($node->title, 0, 60the title just vanishes!Edited : This problem is solved by using
drupal_substrinstead ofsubstr. I guesstruncate_utf8can be used also, but no idea how that can be fitted in the above code]Keyz: Could you please be more specific
where I should paste this piece of code please to alter my Recent Comments block (Views)?
Many thanks
Theo Richel
In your theme's
In your theme's template.php, add:
This should do the trick, and without any hacking of the Drupal core. (Code not tested.)
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials
---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com
Drupal functions
There are also some useful Drupal functions for this:
http://api.drupal.org/api/file/includes/unicode.inc/5
Hans
KOBA - Drupal Webdevelopment
KOBA - Drupal Webdesign & Webdevelopment