2012-12-28 45 views
0

我有一些代碼在我的模板:實施addtag在Drupal模板

$query = new EntityFieldQuery(); 
    $entities = $query->entityCondition('entity_type', 'node') 
    ->propertyCondition('type', 'article') 
    ->propertyCondition('status', 1) 
    ->fieldCondition('field_show_on', 'tid', $group['identifier'], '=') // taxonomy identifier 
    ->fieldCondition('field_perks_categories', 'tid', $categories['tid'], '=') 
    ->fieldCondition('field_perks_sub_categories', 'tid', $subcategory['tid'], '=') 
    ->execute(); 

我還有其他的表名爲「artc_order」的內容NID,重量訂購物品手動 我要實現這一點: http://eureka.ykyuen.info/2012/05/16/drupal-7-order-entityfieldquery-by-random-using-hook_query_tag_alter/ 到我的模板文件,該怎麼做?

+0

關於我的問題的另一個鏈接。然而它是在模塊上實現的。我可以在模板上實現它嗎? http://drupal.stackexchange.com/questions/45785/entityfieldquery-inner-join/54277#54277 – kelaskakap

+0

感謝您的信息 – kelaskakap

回答

0

也許這是有用的使用db_select您的情況,而不是EntityFieldQuery()。你不能直接添加JOINEntityFieldQuery因爲它不支持,也許在Drupal 8

你的查詢可以與db_select被rewritted這樣的:

$query = db_select('node', 'n') 
     ->fields('n', array('nid')) 
     ->leftJoin('field_data_field_show_on', 'fso', 'fso.entity_id = n.nid') // You can use INNER if you need 
     ->leftJoin('field_data_field_perks_categories', 'fpc', 'fpc.entity_id = n.nid') // Same thing here 
     ->leftJoin('field_data_field_perks_sub_categories', 'fpsc', 'fpsc.entity_id = n.nid') // And here also 
     ->leftJoin('order', 'o', 'o.nid = n.nid') // Join artc_order 
     ->condition('n.type', 'article', 'LIKE') 
     ->condition('fso.field_show_on_tid', $group['identifier']) 
     ->condition('fso.field_perks_categories_tid', $categories['tid']) 
     ->condition('fso.field_perks_sub_categories_tid', $subcategory['tid']) 
     ->condition('n.status', 1) 
     ->orderBy('o.weight') 
     ->execute(); 

PS:我不能對此進行測試查詢,因爲我沒有你的數據庫,但幾乎是這樣。

PS2:使用查詢到的template.php文件不是一個乾淨的方法,我知道,在某些極端情況下,我們需要做的,但我認爲,Drupal有很多掛鉤,使我們對什麼我們需要在我們的自定義模塊中,而不是template.php直接(這只是我的意見,我可能是錯的)

+0

謝謝,這是非常有益的。我更喜歡你的查詢,它的工作 – kelaskakap