OK ... times like this, I really wish I were a real programmer, rather than just a wooden boy.

OK .. I'm looking through the available PHP snippets, and I've found some that will get me node, with teasers from a specific taxonomy term. And I've found some that will get me a list of titles from a specific taxonomy term. Now, is there some way to meld the two concepts so that I generate the title and teaser from the most recent node in a term, followed by simple title (and author) links to, say, the next five?

I also wish I had a budget so I could hire a programmer to do this for me ...

--|PW|--

Comments

Dublin Drupaller’s picture

You could combine the two snippets in the same page..i.e.

Snippet 1: ">Display (x) recent nodes (with teasers) of a specified type from a specified taxonomy term

And add this line in between:

unset ($output); 

The unset command essentially "clears" the $output results so one can have another php snippet creating output. more details are on the using more than one snippet in the same page handbook page.

Snippet 2: Display a list of node titles from a specific category

Hope that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

Dublin Drupaller’s picture

Hope the above is of use..if you run into difficulties, post back up here.

As another alternative approach..which doesn't require the unset thing mentioned earlier..

  1. paste the two snippets into a page. (CREATE CONTENT -->> PAGE)
  2. in snippet 1, remove the print $output; line and rename the $output string to be called $output-top
  3. in the second snippet remove the print $output; line and rename the $output string name to be $output-list.
  4. adjust the variables at the top of each snippet, such as the terms, list length etc.
  5. At the end of the page, insert the following snippet, it should be self explanatory and give you ideas on how you can manipulate content in a page
print "<table><tr><td>"; // create a table 
print "$output-top"; // print out the node with teaser
print "</td><td>";  // close and create a new table cell
print "$output-list";  // print out the node list
print "</td></tr></table>"; //close the table.

Of course instead of a table..it could be a DIV or some custom formatting...I hope that makes sense and sparks a few ideas...

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

pobster’s picture

It should work! :o)

/**
* This php snippet displays content of a specified type, with a teaser
* followed by a list of the following 'x' node titles with a link to each node
* from certain taxonomy term.
* Sorted by date of creation, most recent first.
* Works with nodes of the flexinode type too.
* To change the length of the list, change $listlength.
* To change the taxomony term, change $taxo_id.
* To change the type of content listed, change the $content_type.
* Tested with Drupal 4.6.3
*/
$listlength="5";
$taxo_id = 1;
$content_type = 'story';
unset ($output);
$result1 = pager_query(db_rewrite_sql("SELECT n.title, n.nid, n.created 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"), $listlength);
while ($node = db_fetch_object($result1)) {
if (!$output) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
$output .= "<p><ul>";
$node = db_fetch_object($result1);
}
$output .= "<li>".l($node->title, "node/$node->nid")."</li>";
}
$output .= "</ul></p>";
print $output;

Pobster

pennywit’s picture

Hey, thanks! If it works, shall it be appended to the sliced bread snippets?

--|PW|--

pennywit’s picture

Sorry I'm such a moron about this ...

If I wanted to put in the author's name ahead of each listed node, how would I add in that?

--|PW|--

Dublin Drupaller’s picture

Hi Pennywit...

I stumbled across this earlier...click through to the fellowsrdvp.org site and have a look at the Most recent Blog entries on the front page..

They have the most recent weblog in teaser + author info, followed by the next 5 most recent weblog titles.. the Drupaller in charge of that site has typed up an explanation of how he did it in the Sliced Bread Snippets page of the Drupal handbook.

Hope that helps..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

pobster’s picture

Oops sorry popped out to go shopping! Yeah no worries, sorry I didn't read your specs properly else I would have put the author in it the first time round. N'mind done now - here it is:

/**
* This php snippet displays content of a specified type, with a teaser
* followed by a list of the following 'x' node titles with a link to each node
* (also showing the nodes author)
* from certain taxonomy term.
* Sorted by date of creation, most recent first.
* Works with nodes of the flexinode type too.
* To change the length of the list, change $listlength.
* To change the taxomony term, change $taxo_id.
* To change the type of content listed, change the $content_type.
* Tested with Drupal 4.6.3
*/
$listlength="5";
$taxo_id = 1;
$content_type = 'story';
unset ($output);
$result1 = pager_query(db_rewrite_sql("SELECT n.title, n.nid, 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)) {
if (!$output) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
$output .= "<p><ul>";
continue;
}
$output .= "<li>".l($node->title, "node/$node->nid") . " <em>Submitted by " . $node->name . "</em>" . "</li>";
}
$output .= "</ul></p>";
print $output;

I've submitted it to the php snippets page already ;o) I like having a good presence there! BTW, I'm no programmer either hence how comes I only just found the command 'continue;' to loop the while erm... loop (!) back to the start rather than just recall the db query. Looks a lot nicer now :o)

Pobster