I'm using drupal 4.7, and wanted to use teasers for the main page.

I tried this code from here http://drupal.org/node/30967#comment-79533 :

<?php
$listlength="1";
$charlength="150";
$taxo_id = 1;
$content_type = 'story';
unset ($output);
$result1 = pager_query("SELECT n.title, n.nid, n.teaser, n.uid, n.created, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = '$content_type' AND term_node.tid = $taxo_id AND n.status = 1 ORDER BY n.created DESC", $listlength);
while ($node = db_fetch_object($result1)) {
$output .= l($node->title, "node/$node->nid") . "<br>" . substr(strip_tags($node->teaser), 0, $charlength) . "... <em>Submitted by " . $node->name . "</em>";
}
$output .= "<br>";
print $output;
?>

And I get this error:

user warning: Unknown column 'n.teaser' in 'field list' query: SELECT n.title, n.nid, n.teaser, n.uid, n.created, u.name FROM node n INNER JOIN users u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = 'story' AND term_node.tid = 1 AND n.status = 1 ORDER BY n.created DESC LIMIT 0, 1 in /home/comedyc/public_html/content/includes/database.mysql.inc on line 120.

Any suggestions?

Comments

jko’s picture

You'd better should look at your database. The n.* stuff represents your database. Therefor, find out what you should/could put in place for the n. by looking at your database?

prettyeyes’s picture

How do I go about doing that, once I get to the database? I don't know what to replace it with.

prettyeyes’s picture

ANYONE??????????

pwolanin’s picture

I think this code is for 4.6 NOT 4.7. The database structure has changed. This might help: http://drupal.org/node/70369#comment-131933

---
Work: BioRAFT

prettyeyes’s picture

Okay, it mentions a template.php. I'm using the phptemplate engine, but I don't see a template.php anywhere. I'm trying to see where I can get it,but I'm looking in all the wrong places. Do you know where I can spot it?

pwolanin’s picture

With the other post, the output function was getting defined there. If your theme folder doesn't have a template.php, just create the file. See: http://drupal.org/phptemplate

Anyhow, the latter part of the code above will work to generate the output, but not to load the data.

Also, I'm not sure I really understand wht you're trying to achieve. You can just set all nodes of type 'story' to be promoted to the front page.

---
Work: BioRAFT

prettyeyes’s picture

Let me start this over.

I'm using the front_page module, as the main page has a slightly different theme than the rest.

On that page, there are EIGHT boxes. There's two boxes on the first row, three boxes on the second row, and three boxes on the third row. I created different node types for each subject, and each subject is to have their own box with their own teasers.

I created a template.php with:

/**
* Catch the phptheme_item_list function, and redirect through the template api
*/
function phptemplate_item_list($items = array(), $title = NULL) {
  // Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
  // will be assigned within your template.
  return _phptemplate_callback('item_list', array('items' => $items, 'title' => $title));
}
function format_node_columns($node) {
  return _phptemplate_callback('node_columns', array('node' => $node));
}

And I created an item_list.tpl.php, but it has nothing in it. I'm confused about that one (Does anyone know if I need this file for my case, and am a little confused about template.php too. ?)

I used this snippet and put it in page.tpl.php:

$listlength="1";
$charlength="150";
$taxo_id = 1;
$content_type = 'story';
unset ($output);
$result1 = pager_query("SELECT n.title, n.nid, n.teaser, n.uid, n.created, u.name FROM {node} n INNER JOIN {users} u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = '$content_type' AND term_node.tid = $taxo_id AND n.status = 1 ORDER BY n.created DESC", $listlength);
while ($node = db_fetch_object($result1)) {
$output .= l($node->title, "node/$node->nid") . "<br>" . substr(strip_tags($node->teaser), 0, $charlength) . "... <em>Submitted by " . $node->name . "</em>";
}
$output .= "<br>";
print $output;

And got this error:

user warning: Unknown column 'n.teaser' in 'field list' query: SELECT n.title, n.nid, n.teaser, n.uid, n.created, u.name FROM node n INNER JOIN users u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = 'story' AND term_node.tid = 1 AND n.status = 1 ORDER BY n.created DESC LIMIT 0, 1 in /home/comedyc/public_html/content/includes/database.mysql.inc on line 120.

I don't want a list of titles, but actual teasers that show the first few lines of the node's paragraph.

pwolanin’s picture

The above SQL will not work. See the page I sent you to above for a working query/loop logic.

Also, do you really need a differnt node type for each box? Why not just a different taxonomy term?

Anhow the latter part is fine. Try something like:

  $listlength = 2; // [maximum] number of titles to show.
  $taxo_id = 12;  // the desired term ID.
  $charlength="150";
  $content_type = 'story';

  $res = db_query_range(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = '$content_type'  AND term_node.tid = $taxo_id AND n.status = 1 ORDER BY n.created DESC"), 0, $listlength);
  $output='';
  while ( $anode = db_fetch_object($res) ) {
    $node = node_load($anode->nid);
    $output .= l($node->title, "node/$node->nid") . "<br>" . substr(strip_tags($node->teaser), 0, $charlength) . "... <em>Submitted by " . $node->name . "</em>";
  }
  $output .= "<br>";
  print $output;

---
Work: BioRAFT

prettyeyes’s picture

That one I tried didn't work. I didn't get any errors, it just shows up blank. And I made sure that the tax id number that I used existed.

jferjan’s picture

I modified code for 4.7 like these...

<?php
$listlength="1";
$charlength="150";
$taxo_id = 1;
$content_type = 'story';
unset ($output);
$result1 = pager_query("SELECT n.title, n.nid, nr.teaser, n.uid, n.created, u.name FROM {node} n join {node_revisions} nr on (n.nid = nr.nid and n.vid = nr.vid) INNER JOIN {users} u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid WHERE n.type = '$content_type' AND term_node.tid = $taxo_id AND n.status = 1 ORDER BY n.created DESC", $listlength);
while ($node = db_fetch_object($result1)) {
$output .= l($node->title, "node/$node->nid") . "<br>" . substr(strip_tags($node->teaser), 0, $charlength) ."...";
}
$output .= "<br>";
print $output;
?>

now im looking for the way to strip img_assist code too ...no luck so far

www.ferjan.net