Hi, I am not a coder - but I thought I could use this module to shorten long node titles so that they can be displayed as a Views 2 block. I found this code snippet and thougt it should work:
function trunc($phrase, $max_words)
{
$phrase_array = explode(' ',$phrase);
if(count($phrase_array) > $max_words && $max_words > 0)
$phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...';
return $phrase;
}
$node_field[0]['value'] = trunc($node->title['value'],4);
But what I get is only the first letter of the title. I don't know the correct syntax - if I try to use $node->title[0]['value'] (as given in the example code below the box), I get some major error.
Any help would be greatly appreciated.
I think this module can help - and I really need a way to get short titles for display on a Views 2 block. Thanks again.
Comments
Comment #1
Moonshine commentedSooo close :)
"Title" is a field added by core's node module, so syntax is a little different then CCK. Try this:
Comment #2
ramper commentedThanks a lot Moonshine - that works! That should fit nicely on my Views block :)
(On a different note, I am put in a position where I have to choose between the dev and official versions of Views 2 - as at least one other module that I need hasn't updated to 'talk to' the new Views 2 API... And the current official version of Views 2 cannot pick up on the CCK fields, if I understand right...Well, at least these jargons are starting to make sense to me - so that's a plus, I guess... :)
Comment #3
Moonshine commentedWell at this point I *think* most of the views related projects have been updated for the recent Views2 api change. I know CCK, nodequeue, date/calendar, link and others are ready. Many others should be compatible via the CCK update, so it's getting relatively safe to move to it. (Backups always help :) )
That said, the latest Views2 release also has a potentially massive performance improvement built in re: access controls. On the views heavy site I'm working with right now page times dropped 50% in some cases. :)
Comment #4
spiffyd commentedCan someone clarify where to put this code snippet?
This allows me to truncate the node titles displayed in views right? If so, any plans to continue development and perhaps introduce this feature:
Selectable options/configuration settings in Views GUI for Node Title fields?
Comment #5
andrenoronha commentedHello, I need some help in a different but related thing:
I use a block created with views displaying one node.
I would like to call the title of the node in my block template... but $node->title doesn't work.
But I use this at template.php:
And it worked in another block template...there i'm using $node->type in the classes list of css...
But my main block.tpl.php file ignores it...
I'd like to do this:
<?php if (!$block->subject) $block->subject = $node->tittle; ?>any idea?? thanks...
Comment #6
phifeshaheed commentedwhere in the code do you place that code snippet?
Comment #7
andrenoronha commentedthanks...but nevermind...
Comment #8
mmjvb commented