After tearing my hair out trying to do a block with titles and teasers from a CCK custom content type using Views, and seeing that other people were having trouble, I sat down with phpMyAdmin, used var_dump($whatever) in the appropriate place and figured out something that worked for me. Maybe it will help you ...
Teaser lists in Views don't work. You get the whole text. It's a bug, somewhere. However, the teaser you want is there in $node->teaser but Views doesn't seem to be able to reference it. There's Node: Body, but no Node: Teaser and Excerpt doesn't seem to work with CCK/Views either (besides, why should I do the work ...).
The custom fields you create are also there but buried two layers down in an array, in the "value" element of an array that is in the 0th element of a top level array. A complication is that all your custom defined fields are given the equivalent of a table prefix with "field_" prepended and are truncated to 31 characters overall (i.e. including the field_ bit). If you want to use the image custom content type, it gets even more complicated ...
So, in coding up a block to do title, teaser and image and a couple of custom fields from a CCK content type, here's what worked for me. My custom content type is called News Editorial, which CCK then referes to as "content_news_editorial" (note how it converts to lower case and puts in underscores for you - and without telling you). My custom fields are called "Editorial Author", "Editorial Author Picture", "Editorial Author Job Title", "Editorial Author Organisation" and "Editorial Content".
The resulting fields in CCK are "field_editorial_author", "field_editorial_author_picture", "field_editorial_author_job_titl", "field_editorial_author_organisa", and "field_editorial_content" (note the truncations)
Here's the code for the block which may help you as an example to get going:
<?php
/*
* Get Latest News Editorial
* ASH, 2006-09-26
* (Can be used an general example for CCK content)
*/
$content_type = 'content_news_editorial';
$limit = 5;
global $base_url;
$result1 = db_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = '$content_type' AND n.status = 1 ORDER BY n.created DESC LIMIT $limit"));
while ($node = db_fetch_object($result1)) {
$node_loaded = node_load($node->nid);
$output .= '<strong><a href="' . $base_url . '/?q=node/' . $node->nid . '">' . $node_loaded->title . '</strong></a>';
$output .= '<p> <br>';
$output .= '<img src="' . $base_url . '/' . $node_loaded->field_editorial_author_picture[0][filepath] . '">';
$output .= '<br><strong>';
$output .= $node_loaded->field_editorial_author[0][value];
$output .= '</strong><br>';
$output .= '<em>';
$output .= $node_loaded->field_editorial_author_job_titl[0][value];
$output .= ',<br>';
$output .= $node_loaded->field_editorial_author_organisa[0][value];
$output .= '</em><p>';
$output .= '<div class="content">' . $node_loaded->teaser . '</div>';
$output .= '<div class="more-link"><a href="' . $base_url . '/?q=node/' . $node->nid . '">More...</a></div>';
}
print $output;
?>
Comments
And...
...Pardon my ignorance, but where is this code placed?
It's block code
Create a new block, select the input format of the block body to be PHP, then cut and paste the code into the block body (making sure there is no spurious whitespace - spaces, tabs or blank lines - before or after the php opening and closing tags).
Similar code could also be used in a template but might need adjusting ...
Have you tried the content
Have you tried the content templates / contemplate module?
http://drupal.org/project/contemplate
Very easy to define teasers and works for views.
Do teasers work?
I've got a similar problem with teasers on a CCK content type. Are you sure Contemplate works?
I've used Contemplate to try and solve this as I'm using Views to produce the summary page. $teaser just pulls out the full content body.
I'm probably missing something. Do you need to use any custom code under Contemplate to trim the Teaser?
Hope
I've set up "introduction"
I've set up "introduction" fields - which are included alongside a photo for the teaser.
There's also this code you can use in contemplate (not mine), that prints only a certain number of characters from the article as the teaser:
<?php print $teaser = substr($field_story_text[0]['value'], 0, 300) ?><a href="<?php print $path ?>">...readmore</a></div>I don't know about the
I don't know about the original asker, but I tried contemplate, and I'm still having problems.
I installed CCK and added books as a custom content type.
Then I installed views and the contemplate module, and tried to get it to make a very simple list of all the books in the site database. It insists on putting the title on it's own line in bold and the person who added the book to the database and the date on the line below. I don't want that information listed. I just want $title by $authorfirstname $authorlastname. But when I tell contemplate module that, it ignores me. :(
At least I successfully killed all the field lables.
Should update this since I'm
Should update this since I'm not using contemplate to do any of this any more.
In 5.x CCK has the option to define which fields and which options appear in teasers in "display fields", along with whether the the field title is displayed. So a lot of the things that contemplate or .tpl.php files were necessary for before, you can now do from within "display fields" in CCK - stuff like using imagecache for thumbnails etc. Then you can do most of the rest with css.
can find the option "display fields"
really interested in this solution - i am using drupal 5 and just cant seem to find this configuration option that you speak of - i would really appreciate giving me a path to this - thanks in advance
henns20
never mind had an older version of cck i guess
couldn't figure out how to do delete my last comment- i updated my cck module and that option showed up--looking forward to using it thanks for the info
henns20
It works!
Thanks SO much for this fix. Very, very helpful.
Just one more question: When I post new content, my old teasers still show up in addition to the block content, thus creating a duplicate on the front page. How can I stop that? Do I need to get rid of Contemplate?
Scratch that....
just a simple question of not promoting to front page.
Thanks!
Link from CCK not showing up correctly...
Thanks again for this great solution. One little thing - when I tried to use a Link field from CCK, it output as the word Array. What does that mean? Any help would be greatly appreciated.
Deleted my comment
Deleted my comment as was wrong - too early in the morning.
Views
I created my views-list-myccktype.tpl.php with theme wizard
I copy/paste code in template.php file from theme wizard
I add this code in views-list-myccktype.tpl.php but I am receiving error.
Is it possible create a teaser in "views-list-myccktype.tpl.php" (I am creating this views like a block)
I found this works nicely
I found this works nicely when themeing a view.
print $teaser = substr($field_body_value, 0, 300)(substitute $field_body_value with the views field name )
A little bit more elegant solution
If you want to create your teasers more cleanly (instead of abruptly cutting off output after X characters), try reusing Drupal's node_teaser() function:
It uses your site's teaser-length setting from /admin/content/node-settings and looks for either the breakpoint delimiter, the last full paragraph or last complete sentence at which to make a clean cut.
cck and taxonomy
Nice work!
I was using this script to pull in my cck profile form:
$nlimit = 1;$userid = arg(1);$result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'content_test_profile' AND n.status = 1 AND n.uid = $userid ORDER BY n.created ASC"), variable_get('default_nodes_main', $nlimit));print $output2;This script pulls in everything on the profile form including taxonomy terms. It works great but I'm not able to format individual fields the way I am with the your script. My question is how do I get the taxonomy fields to display if I use your script?
Any ideas?
Thanks,
Jim
Taxonomy formatting
Well, the purists would say all this should be done in the theme, but if you are not a CSS wiz (like me), hand-coding is faster :-)
I have done this sort of thing with taxonomy entries in the past but I am currently on holiday away from all (21 of) my machines so can't find you a code example...
If you do a search for "taxonomy terms" or something simliar, you will find examples of how to pull requires taxonomy terms into an array which you can then just iterate over and apply your own formatting to, like my code example.
Sorry can't be of more help right now.
Christmas greetings
A.
WARNING!!
Anyone who used this code on their site (or other snippets like it), please PLEASE read Handle text in a secure fashion.
This code is just printing the CCK field value directly to the browser, without running it through any kind of filter to strip out attempts to use JavaScript, PHP, etc. in it.
Never never never EVER do stuff like this:
$output .= $node_loaded->field_editorial_author[0][value];
'value' is the 'raw' field value.
either use 'view' rather than 'value' (if it's available), or run it through check_plain / check_markup, whichever is more appropriate:
$output .= check_plain($node_loaded->field_editorial_author[0][value]);
Absolutely right
Webchick is, of course, absolutely right.
In my defence, I would point out that when I wrote this I had been using Drupal for about 3 days, the views and CCK modules were in their early stages and that the pages I was retrieving had only trusted input from a system administrator but that's no excuse ...
I would also point out that I think the "Handle text in a secure fashion" page is not easy to understand and includes insufficient examples, especially when dealing with CCK, views, contemplate, etc
subscribing
subscribing