3

For a blog homepage I am trying to output a view that lists a single post for each user on the site. It needs to be sorted by date, so the latest post is shown at the top.

I'm trying the 'view inside a view' method here http://groups.drupal.org/node/11746 but thinking there must be a better solution out there.

2

The solution was to use Rules and Views bulk operations (VBO) to change the 'promoted to front page' property of that users blog posts when they submit a new post. The triggered rule simply removes 'promoted to front page' from all their posts and then adds it back to the newly submitted node. Thus, each user will only have a single blog post with this property, which makes the blog homepage easy as you simply create a view sorted by date and filtered with the 'promoted to front page' property. Johan Falk has done some excellent tutorials on using rules and VBO. Well worth a watch.

1

The first problem is to sort your users properly.
Saying in SQL, you need something like this:

SELECT * FROM node GROUP BY uid ORDER BY MAX(created) desc;

As I can see GROUP BY in ORDER part is not going to work in Views 2/3. I may be wrong.
But if number of users on your site is not too big, you still can make this done in PHP argument code like this:

$nodes = db_query("SELECT nid FROM {node} GROUP BY uid ORDER BY MAX(created) desc");
$items = array();
while ($node = db_fetch_object($nodes)) {
  $items[] = $node->nid;
}
return implode('+', $items);

This code returns IDs for nodes, which have to be displayed. Now you have sorted nodes for each user and you can play with outputting.

2
  • 1
    The SQL statement could have done the trick, but I decided to take a completely different approach by simply using the 'promoted to front page' property. I used Rules and VBO to set and unset this property automatically upon submission of a new blog node. I could then use a simple filter in views to output my blog homepage. Aug 18 '11 at 12:45
  • Good job! I think you could update your question to point people that you found solution.
    – kalabro
    Aug 18 '11 at 13:07

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.