欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

hook_views_query_alter Drupal 6.x (substring) 例子

shiping1 的头像
  1. /**
  2. * Implementation of hook_views_query_alter().
  3. */
  4. function local_views_query_alter(&$view, &$query) {
  5. if ($view->name == 'our_partners' && $view->current_display == 'page_1') {
  6. //alter the query so we actually select the results with the surname begining with the arg
  7. $query->where[0]['clauses'][3] = "SUBSTR(reverse(node.title), locate(' ', reverse(node.title)) - 1, 1) = '%s'";
  8. }
  9. if($view->name == 'our_people' && $view->current_display == 'page_1') {
  10. //alter the query so we actually select the results with the surname begining with the arg
  11. $query->where[0]['clauses'][2] = "SUBSTR(reverse(node.title), locate(' ', reverse(node.title)) - 1, 1) = '%s'";
  12. }
  13. if($view->name == 'our_people' && $view->current_display == 'attachment_1') {
  14. //alter the query so we actually select the results with the surname begining with the arg
  15. $query->fields['title_truncated']['field'] = "SUBSTRING( reverse( TRIM( node.title ) ) , locate( ' ', reverse( TRIM( node.title ) ) ) -1, 1 )";
  16. }
  17. if($view->name == 'our_partners' && $view->current_display == 'attachment_1') {
  18. //alter the query so we actually select the results with the surname begining with the arg
  19. $query->fields['title_truncated']['field'] = "SUBSTRING( reverse( TRIM( node.title ) ) , locate( ' ', reverse( TRIM( node.title ) ) ) -1, 1 )";
普通分类: