2

I'm sure this is possible, I'm just looking for some advice on the best way to approach it.

Here's the situation:

We have some English content. If the user is in Australia, we want to show them all content, with Australian tagged content sticky at the top. If the user is from another English speaking country, we will just show them all content in normal reverse chronological order.

At present, we are tagging content with Locations using locations.module. I have some code in hook_init which identifies the user's country, which is stored in their session.

I figure using an argument to locations.module's views argument support is the best way to do this, but we can happily use another solution like taxonomy if that is more appropriate.

Any ideas on how best to configure a view like this?

3

I ended up using this code to get the desired functionality:

function mymodule_views_query_alter(&$view, &$query) {
  // in my case I'm pulling info from the user object to decide the sort,
  // but obviously you could check anything here. Use arg($x) to read URL arguments.
  global $user;
  if ($user->country == 'AU') {
    // Note in this case NULL is above AU, so descending order it is.
    $query->orderby = array_merge(array('location_country DESC'), $query->orderby);
  }
}

I'd love to hear any other thoughts on good ways to do this, particuarly some guidance with adding sort objects to the view using hook_views_pre_execute or similar.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.