Listing certain products on specific content pages

Posts: 48
Joined: 01/31/2008

Is there a way to list either by category or by selection of a few product on specified content pages. So if you have a content page of red tshirt, at the bottom of it will display red tshirts from the catalog...

Posts: 10
Joined: 01/28/2008
Cool profile pic award.

Yes you can.. although I believe you need to use custom php to achieve this.

Take this code for example:

//get node IDs from a particular category

function getNodesTerm($term) {
$obj = taxonomy_get_term_by_name($term);
$res = db_query("SELECT * FROM term_node WHERE tid='".$obj[0]->tid."'");
$count = db_num_rows($res);
  for ($i=0; $i<$count; $i++) {
        $out = db_fetch_object($res);
        $nodes[] = $out->nid;
  }
  return $nodes;
}

Usage:
Theoretically, you can use it like this..

//load all red shirts
$node_arr = getNodesTerm("red shirts");
for($i=0; $i<count($node_arr); $i++) {
print node_view(node_load($node_arr[$i])); # print each product.
}

As this code's comment says, it fetches all the nids of nodes classified by a specific category. And from there, you can use the nids for your own purpose. I used the taxonomy module's function taxonomy_get_term_by_name() to get the object containing the term Id (tid), and use it to fetch the node IDs that fall under that category.

Posts: 27
Joined: 01/31/2008

I think "Views" can help you here.

With "Views" you can create custom tables or lists or grids of particular nodes (for instance to list all nodes with the term "red"). Or you can let views create a block which will list all red t-shits. And this block you could set to be visible only on certain nodes.

Also the module "viewfield" would enable you to insert views into nodes, if not as a block.

Posts: 48
Joined: 01/31/2008

Thank you both! As I'm still trying to get used to using views, does anyone have basic steps by steps - or have links to tutorials on using views like this?