I've managed to find modules and snippets that will put node teasers in another node from one module only though. What I need to do is this;

ie. online magazine has it's own content modules of;
(examples only for explanation)
a. trucks
b. cars
c. vans

I have a node that has the teasers of the most recent truck articles and I have a node that has the most recent car teasers.

but how do I make a node that pulls the most recent node with one teaser from the trucks content, one teaser from the cars content, etc. and vans in a new node called vehicles.

This is what I'm using to do the node teasers for the individual node sections, ie. trucks. But I can't see how to pull in from different nodes for a comprehensive teaser list.

/**
* This php snippet displays content of a specified type, with teasers
*
* To change the type of content listed, change the $content_type.
*
* Works with drupal 4.6
*/
  $content_type = 'trucks;
  $result1 = pager_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 ASC"));
  while ($node = db_fetch_object($result1)) {
    $output .= node_view(node_load(array('nid' => $node->nid)), 1);
  }
print $output;

Thanks,
Lisa

Comments

pwolanin’s picture

try something like this:

  $result1 = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.type in ('trucks', 'cars', 'vans') AND n.status = 1 ORDER BY n.created ASC"));
  while ($node = db_fetch_object($result1)) {
    $output .= node_view(node_load($node->nid), TRUE);
  }
print $output;

OR, if you're going to need to pass in the types:

  $content_types = array('trucks', 'cars', 'vans');
  $result1 = db_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type in ('". implode("', '", $content_types) ."') AND n.status = 1 ORDER BY n.created ASC"));
  while ($node = db_fetch_object($result1)) {
    $output .= node_view(node_load($node->nid), TRUE);
  }
print $output;

---
Work: BioRAFT

lisar’s picture

thanks:) That worked perfectly!

nevets’s picture

One you might want to check out the views module as it is real handy for these kind of pages.

As for updating the snippet, change the two lines where you set $content_type and where you perform the query to

  $content_types = "'trucks', 'cars', 'vans'";
  $result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type IN ($content_types) AND n.status = 1 ORDER BY n.created ASC"));

lisar’s picture

I wanted to install views as it appears to have a lot of the flexibility I need for various modifications. However once installed it doesn't show up in my admin menu, so I'm not sure how to fix that....

lisar’s picture

If I want to put teasers of 5 specific nodes in a node, what would I change the code to? I tried changing $content_type to $node_url but that doesn't seem to work and I probably have to change more and that gets beyond my level of php.

Thanks,
Lisa

pwolanin’s picture

Well, hand-coding the nid values seems a little silly, but easily done as:

  $result1 = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid in (33, 34, 35) AND n.status = 1 ORDER BY n.created ASC"));
  while ($node = db_fetch_object($result1)) {
    $output .= node_view(node_load($node->nid), TRUE);
  }
print $output;

where you should replace (33, 34, 35) with you list of desired nid values.

More typically, you'd do a join, ORDER BY, or WHERE based on some other criteron (like taxonomy a term or timestamp)

---
Work: BioRAFT

lisar’s picture

that worked. The truth is I really don't understand what most of it means, so I just muddle through and so I have no idea what a join, ORDER BY, etc. would even mean;)

thanks:)
Lisa

drowlflood’s picture

To cut down on execution time, just call the individual nodes by their nodeId. For example:

<?php
$output .= node_view(node_load(32), TRUE);
$output .= node_view(node_load(34), TRUE);
$print output;
?>
pwolanin’s picture

oh yes- of course. There's certainly no point in selecting the nids if you know the nids...

---
Work: BioRAFT