$query = db_select('node', 'n')
->join('field_data_field_fenlei', 'c', 'n.nid = c.entity_id')
->join('taxonomy_term_hierarchy', 'th', 'c.field_fenlei_tid = th.tid')
->join('node_type', 'nt', 'n.type = nt.type')
->condition('n.type', 'product')
->condition( db_or()
->condition('th.tid', arg(2), '=')
->condition('th.parent', arg(2), '=') )
->fields('n', array('nid')) // select nid field only so that node_load() will be called later
->extend('PagerDefault') // this adds the pager
->limit(5);
$result = $query->execute();
product is the content type. field_fenlei is the category machine name . which is a select list, contains all the term.
i put the above code in the term template page file, the page shows unnormal(the page doesn't load the header part ....). there is something wrong with the query code?
is there a way to test whether the query code right or not?
$query
object to a string, e.g.print (string) $query;
– Clive♦ Dec 7 '12 at 14:16