Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal Views: Display recent nodes created by user on profile page

I'm wondering how I can display the recently created nodes by a user on their profile page. I've created a new page for a user at /user/%user and I want to be able to display the latest nodes created by that user.

like image 731
Conor Mongey Avatar asked Apr 03 '10 00:04

Conor Mongey


3 Answers

ok, the answer involves creating a drupal view, so you will need the views module and although simple, the answer is lengthy. please bear with me through this... :) (i am actually doing this on a test site as i write the instructions, to make sure i dont miss anything...)

i assume that you know how to download and install the views module. make sure you also enable the views-ui module.

  1. go to site building->views->add.
  2. put "recent_posts_by_user" for view name, "recent posts by user" for description and "node" for view type. hit next.
  3. under the "default" view type, on the "fields" block, hit the "+" sign.
  4. under "groups" select node, then check the "node type", "node title" and "node updated date" fields. hit the "add" button below the list.
  5. under basic settings block (on the left), click on the "10" for "items for display" and change to "5" or however many items you want per page, and hit "update"
  6. under "use pager", click on "no" and "full pager" or "mini pager" and hit "update" again.
  7. under style, hit "unformatted" and change it to "table" set all fields to sortable, then choose the "updated date" as "default sort", then on "default sort order", select "descending". hit update.
  8. hit "save" to save your progress thus far.

default view is done. YAY! lets add the block

  1. now on the drop-down that says "page", select "block" and hit "add display".
  2. hit "arguments" (block title on the center of the screen)
  3. hit "override" and "update"
  4. hit the "+" sign to the right of "arguments"
  5. on the "groups" drop down, select "user" and select "user id". hit "add"
  6. under "Action to take if argument is not present", select the last option "provide default argument", select "user id from url" and check "Also look for a node and use the node author"
  7. under "validator", select "user" and "Allow both numeric UIDs and string usernames"
  8. under "Action to take if argument does not validate" select "hide view/page not found (404)"
  9. hit "update" then "save"

view is created now lets make sure it shows up on the right pages.

  1. go to site building->blocks, search for the "recent posts by user" block and hit "configure"
  2. scroll all the way to the bottom and select "Show on only the listed pages." and put in "users/*" under the "pages" text area
  3. hit "save block"
  4. now find the "recent posts by user" block again and set it to "content bottom" region (or any other region your theme has available).
  5. hit "save blocks"

DONE! Not rocket-science, but lengthy process... drupal 6 views is so much better than drupal 5! :)

now go visit a user page http://site/users/username and see the table show up there!

hit me up if you still have questions about views.

enjoy

like image 177
Peter Carrero Avatar answered Nov 11 '22 15:11

Peter Carrero


Put in a Views Argument that uses the User ID from the URL argument. It will be arg(1). That should filter content that was authored by the profile you are looking at. That can work for a block or content pane.

like image 25
Kevin Avatar answered Nov 11 '22 14:11

Kevin


I just prefer you to go to Views -> Sort Criteria and add the Node:Updated Date and mark it as descending as it shows the granularity over the time.

Moreover, you can also get the most recent node not only to the table style but to all.

like image 21
Bala Avatar answered Nov 11 '22 14:11

Bala