Posted by sterwa on May 26, 2008 at 6:36pm
Hi,
How can I set up a view with one (latest) blog entry per user, sorted by node submission type. Can't seem to figure out how to set up the whole "one node per user" thing...
Thanks!
Hi,
How can I set up a view with one (latest) blog entry per user, sorted by node submission type. Can't seem to figure out how to set up the whole "one node per user" thing...
Thanks!
Comments
That query is actually very
That query is actually very hard to do in SQL and Views does not support the necessary wedges that let you do it.
thanks mate...
thanks mate...
Not quite, but may be useful
http://groups.drupal.org/node/11746
I'm actually thinking of
I'm actually thinking of something similar, but trying to do a view of the latest post of type x from each group and then feed it into a gmap view. Any ideas?
List of users
Though slightly different than original poster was after , I was able to use the arguments in views to create a list of users, each item shows the user's name and then a total of their blog posts, with their name being a link off to their blog. This was really helpful for me, so i thought I'd share...
setup a view, etc...
In arguments, i did "user: Name"
put a "%t" in for the title
in the section titled:
Action to take if argument is not present:
choose summary, sort ascending
(this will produce results in an ascending alphabetical list)
For validator, I chose "user"
and chose the content types I wanted (story and blog)
after hitting sbumit, it will ask you to format in either a list or un-formatted. I chose "list"
the next page asks if you want to include the record count, i chose to check that.
this will produce a list of users (making content), and how much content they have produced. users with no content aren't listed.
YMMV
Solution
This is how you do it.
Embed a view in a view.
That worked for me. *You probably no longer need this - been 2 years - so its just for the record.
Re: Solution
Hi Alexei
Any chance you could elaborate on your solution? I've never tried embedding a view in a view?
In step 2, do I need to install Views Custom Field?
I am trying to create a view that brings back just one node per user.
Any help or clarification would be great!
Thanks
Rachel
In detail:
Say, you have a view of users. Their logos, their names, emails, custom user fields, etc. And you want to have there the last blog post their as well, like this: "Last in blogs: Blog Post Title (May 10, 2010)". Now, you can't get that data from within the same view. You would actually have to have a whole new other view by itself to generate that data. With node title and post date fields. So, this is what you do.
Generate a view with fields of node title and post date. You set the items to show to 1. Sort by post date descending to show the last item. And add an argument - user id.
Download a custom views field module. http://drupal.org/project/views_customfield
Now, back to the users view.
<?php views_embed_view("view_machine_name", "display_machine_name", $uid); ?>Machine name of a display can be "defaults" if you are not using an added extra display.
$uid should be taken from a user->id field. The field itself can be set to not display. Will just take the value.
So, the argument is passed to another view, which displays just one item that we want. There are more comples but less power-hungry ways of course. But this one works.
Thanks so much - but still a bit stuck
Hi Alexei
Sorry to keep taking up your time...
I have followed your instructions, and my user view now brings back the user fields but my php custom field is empty. Maybe I have the syntax for the php snippet wrong?
The view I want to embed has the machine name (I assume this is the View name as listed on the page admin/build/views?):
view_dcc_images_by_user
so my php custom field is set to:
<?phpviews_embed_view("view_dcc_images_by_user", "defaults", $uid);
?>
Any idea where I am going wrong?
Many thanks
Rachel
Hi Rachel. I dont remember if
Hi Rachel. I dont remember if you should have the
<?php...
?>
But first of all, check if there is an argument passed. $uid will not get substituted on its own. Argument should be taken from an existing field in that same view.
Say, you have a user fields that returns user id. You should see the list of available variables or substitutions in your custom field description text. Your view will look something like this:
?phpviews_embed_view("view_dcc_images_by_user", "defaults", [uid]);
?>
I dont remember in which format the substitution variables are presented there - but they should be listed there in the field description.
Getting there...
Well, some progress now.
I needed the php to look like this:
<?phpprint views_embed_view('view_dcc_images_by_user', 'default', [uid]);
?>
So I did need the tags, and I also needed the print statement.
However, I still can't get the [uid] substitution to work. If I hardcode '3' in place of [uid] it brings back the results from view_dcc_images_by_user just fine for user 3. And uid is available as I am bringing it back as a field.
In a separate custom field
<?phpprint $data->uid;
?>
brings back the right uid. How do I pass this as the argument to my embedded view?!!
Many thanks again
Rachel
Hello Rachel, you need to add
Hello Rachel, you need to add a field that would have user id in your view. You can set that field to not display - but it has to be there so you can use it in substitute.
Sorry to still be asking you
Sorry to still be asking you so many questions, I really do appreciate your help.
I already have user id in my view (I assume you mean as a field in my second view?). This displays correctly. I think my problem is with the syntax I am using to refer to the substitution at this step:
<?phpprint views_embed_view('view_dcc_images_by_user', 'default', [uid]);
?>
in place of the text [uid] I have tried:
[uid]
$uid
'[uid]'
'$uid'
None of which bring back a result?
Am I missing something obvious? I am so close to getting this to work!
OK - I think I fixed it! Here
OK - I think I fixed it!
Here is the code I used to get this to work:
<?php
$my_uid='';
$my_uid= $data->uid;
print views_embed_view('view_dcc_images_by_user', 'default', $my_uid);
?>
Alexei - many many thanks for all your help with this!
Rachel
You need to check it out in
You need to check it out in the custom field description. It's in the $data variable. $data->uid - try this.
Thanks Alexei!
Yes, exactly what I needed! Thanks again for all your help.
Oh cool! You applied the code
Oh cool! You applied the code to your context great! You can almost never just copy and make it work. Glad it helped!
Someone just linked me this
Someone just linked me this thread on #drupal-support. Ive been trying to do this for over a year in views - http://drupal.org/node/457738 - but with no success, great to see that it is possible.
Well I now have it up and running too. I have the following columns
Username Latest post Post dateLatest post and post date are both coming from the embedded view, obviously. The problem is I want to sort by post date. So that when users visit my site's blog home page they see a list of Latest posts from all users ordered by post date so that the most recent posts are shown first. Is it possible to this?
Have you tried ordering by
Have you tried ordering by Post date descending in the Sort criteria of the view? I think this should work? If you have problems, let me know and I'll try it on a test view here.
Hi, in the embedded view I
Hi, in the embedded view I have the fields -
Latest Post
Post date
I am ordering by Post date descending in this view to get the latest posts by each user, as described by Alexei Rayu in comment 8 on this thread.
In the 'outter' view I have the fields
Username
Uid(hidden, passed to the embedded view)
Customfield: PHP code (the embedded view showing Latest Post and Post Date)
I can't make the Customfield: PHP code field sortable, I'd appreciate any help you can give me, I've been stuck on this issue for ages.
This might work... Try using
This might work...
Try using file-upload date in the sort criteria?
My embedded view brings back username and the latest image they've uploaded. When I added file-upload sort descending to my view, it then sorted on the date the image was uploaded (even though this wasn't in my view).
But I really don't know if this would work with comments? (It probably shouldn't, as they're not files).
Please post if this works or not - if not I'll get my thinking cap on (but about to go on a 2 week holiday...so might have to think when I get back!)
PS The other way to do this
PS The other way to do this might well be through theming the output. I've only just started trying this, and I've only worked with pages, whereas I'm guessing you're using a block. If you want a reference to start with, try this podcast on views theming at
http://mustardseedmedia.com/podcast/episode23 - in fact I've watched a lot of Bob's podcasts at mustardseed, and I think they're great, I've learnt loads from him.
Ive actually got a good bit
Ive actually got a good bit of experience theming views so Im ok in that department.
regarding your previous comment, what fields are you using in your embedded view and your outter view? I don't have file-upload date as I am purely dealing with blog posts. I have Created date, but as I said I sort by that in the embedded view to get the latest post. I can't sort by that in the outter view which is what I need to do to get the list of all users latest blogs posts sorted from most recent to oldest - like on this site http://www.cardrunners.com/blog/featured/
If you need sorting
If you need sorting by date try to make date into the main field and the other data pushed into embedded view. That is the only thing I can imagine if the custom field is not sortable.
Views 3.3 + Drupal
Views 3.3 + Drupal 7.14
http://drupal.org/node/1691804#comment-6253298
I achieved views into another
I achieved views into another views with http://drupal.org/project/views_field_view module.