The taxonomy module outputs a list of nodes which generally includes title, submission details, links, and teaser. This is fine for the front page, but is there any way to have taxonomy output, for example, just the title and name of poster in a simple list, without all the additional details? So when you click on a link such as taxonomy/page/or/34 you get something like:

Story title 1, submitted by John
Story title 2, submitted by Alice
Story title 3, submitted by Mary...

Comments

tdailey’s picture

node_title_list is a built-in function that almost does what you want.
You'll just need some PHP code like this:

  $taxdisplay->operator = "or";
  $taxdisplay->tids = array(11);
  $taxdisplay->str_tids = "11";

   print node_title_list(taxonomy_select_nodes($taxdisplay, 0));

You can customize the node_title_list function (maybe make a node_title_list_custom for yourself) to include any custom info from the node(s) that you might want.

If you use the built-in taxonomy_menu module, you can do this within the menu by changing the taxonomy_menu_page function. Just change:

taxonomy_render_nodes(taxonomy_select_nodes($taxonomy));

to

print node_title_list(taxonomy_select_nodes($taxonomy));

This will change your default display in taxonomy_menu from a rendered list of full stories to a list of titles only.

droopy’s picture

Thanks for this - but I'm not sure where I should put the PHP code that you provided:

$taxdisplay->operator = "or";
$taxdisplay->tids = array(11);
$taxdisplay->str_tids = "11";

print node_title_list(taxonomy_select_nodes($taxdisplay, 0));

Besides, I think I would rather change the default behaviour of taxonomy globally so that all output is just a list of titles and authors. How would I change taxonomy_render_nodes() to make use of node_title_list rather than node_view?

function taxonomy_render_nodes($result) {

  while ($node = db_fetch_object($result)) {
    $output .= node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1);
  }
  $output .= theme("pager", NULL, variable_get("default_nodes_main", 10), 0);
  return $output;
}
tdailey’s picture

You just put that sample code into a static PHP node page or a block.

rather than change taxonomy_render_nodes, just change taxonomy_page.

Change
taxonomy_render_nodes(taxonomy_select_nodes($taxonomy));
to
print node_title_list(taxonomy_select_nodes($taxonomy));

I think this gives you the desired function you want. Now, when someone goes to /?q=taxonomy/page/or/11 , for example, they get a list of taxonomy nodes rather than the entire story.

jibbajabba’s picture

If you want to show node entries as simple lists with partial field displays, e.g. title, author, rather than displaying the entire blog entry, you can try what I've done. Look at the display of nodes on taxonomy pages on my familytravelog blog and come back here -- search for "function node". I did this by modifying the theme's node function (a lot). I'm basically checking if Drupal is serving a $main page -- e.g. main blog pages, taxonomy pages vs. individual node pages -- and giving a stripped down display using list tags for that, or else give them the full-blown node display. My node display on that theme includes more complex displays for my "review" type node.

Basically this involved changing function node like this:

[?
   // index pages vs. others
  if ($main) {

    echo "

  • nid\">$node->title
    ";
        print
        t("%a", array("%a" => format_date($node->created, "short"))) ."";
        print " in $node->type entries

";

  // not index pages  
  } else {
// normal node code goes here
}

?]

View the source for my theme file here.

I don't if there is something wrong with this method, but it works for me. Why muck around with the core modules when you can just hack the theme?

tdailey’s picture

I don't if there is something wrong with this method, but it works for me. Why muck around with the core modules when you can just hack the theme?

I don't see anything wrong with your method. It's more flexible, but it also looks like a lot more work. I use xtemplate as a base and it looks pretty complex to pull that off in the xtemplate theme.

I thing the delimiter would be whether you want the change globally or on a selectable basis. Certainly the one line hack above is simpler than hacking the theme. :)

droopy’s picture

I like the theme based solution because of the formatting flexibility, but it appears to produce a cut-down list for the front page as well as for output from the taxonomy module. I would like the normal heading - teaser - links display on the front page of the site and the cutdown version (heading - author) on all taxonomy output (eg. taxonomy/page/or/31). Is the theme node function able to differentiate between the front page and all other requests for lists of nodes? I hope I'm making myself clear. Thanks for the help.

jibbajabba’s picture

So I guess you have to figure out when you're on the home page, and then just add fields to your liking, e.g. $node->teaser or whatever for that page and do simple display elsewhere.

droopy’s picture

I can't figure that one out on my own. Can you (or anyone else) explain to me how to have a full node listing (with title, author, teaser, links, etc.) for the home page and a simplified listing (eg. title and author only) for all other output (eg. as a default for taxonomy output). I think this would be a useful option in Drupal. By the way, I'm using 4.2 at the moment though I plan to upgrade when 4.4 appears.

jibbajabba’s picture

I don't know if this is the best way to do this, but you can modify the node function to check to see if the browser is serving the home page, assuming your home page is at the root of your domain, e.g. http://somedomain.com. Like below. I'm sure somebody else can do it a better way, but this might be a serviceable solution.

[?
$dapath = $_SERVER["REQUEST_URI"];

// home page
if ( $main && eregi("^/$",$dapath) ) {

print "

$node->title
";
if ($main && $node->teaser) {
print "$node->teaser
\n";
} else {
print "$node->body
\n";
}
print t("Submitted by %a on %b", array("%a" => format_name($node), "%b" => format_date($node->created, "large"))) ."
";
print "$this->links($links)

";

// other pages
} else {

print "

$node->title, ". t("Submitted by %a on %b", array("%a" => format_name($node), "%b" => format_date($node->created, "short"))) ."

";

}
?]

droopy’s picture

I couldn't get the theme based approach to work with xtemplate so here's what I did instead. I modified taxonomy_render_nodes in taxonomy.module using code from node_title_list() in node.module. I duplicated theme_item_list as theme_short_list() in theme.inc so that I could avoid using the item-list class. You can see the resulting output here. The front page has the normal node listing. This is now pretty much as I wanted it. Thanks for all the guidance.

tdailey’s picture

thanks for the idea, i took what you did and adapted it for my page too.