Ok, So I have a site that has user profiles, very basic ones. These users are allow to create nodes of the type "listing". What I'm trying to accomplish is to create a link on each user's profile page that will take you to a list of nodes that they have created. In essence, like the tracker button but not using the tracker button and limiting the results to a certain content type. What I have done so far is sooo close I just can't seem to figure out the rest. I've got a custom page template for user profiles and I've added this:
<?php $result=db_query("SELECT distinct n.uid, name FROM node n inner join users u on n.uid=u.uid WHERE type='listing' and n.status=1 order by name asc");
while($obj=db_fetch_object($result)){
print '<h3><a href="/user/' .$obj->uid. '/tracker">'.$obj->name.'</a></h3>';
}
?>This prints out a list of all users that links to content created only by them. How can I get it to only show the user's name for the user profile you're viewing? Does that make sense?
Any help or other ideas of how to show content created by a specific user on their profile page, viewable by all, would be much appreciated! Thanks!
Comments
Clarification: Really all I
Clarification: Really all I need to do is grab the uid of the user's profile you're viewing. I tried var_dumping the $user variable but it only returns info. for the currently logged in user, not the information for the user profile you're currently viewing. Using dev load I can see that information that I need to get to is being loaded on the profile pages, I just can't figure out how to access them and print them with php. For example:
<?php print $user->uid;?>returns the uid of the currently logged in user, not the uid of the user profile you're on. Help! I tried var_dumping all kinds of variables but can't figure out where the information I need is being stored. If I could just access that uid I'd be good to go!overload hook_user
hi
to show users nodes on there profile page
you have to overload the hook_user()'s view action
http://api.drupal.org/api/function/hook_user
and you can make list of nodes created by that user
<?phpfunction blog_user($type, &$edit, &$user) {
if ($type == 'view' && user_access('create blog entries', $user)) {
$user->content['summary']['blog'] = array(
'#type' => 'user_profile_item',
'#title' => t('Blog'),
'#value' => l(t('View recent blog entries'), "blog/$user->uid", array('attributes' => array('title' => t("Read @username's latest blog entries.", array('@username' => $user->name))))),
'#attributes' => array('class' => 'blog'),
);
}
}
?>
and to grab the uid of the profile
you can use arg(1)
drupal user path is like www.yoursite.com/user/1
so printing arg(1) it will give you the
uid of current profile
<?phpprint arg(1);
// run this code on user profile page it will give current profiles uid
?>
thanks
How about this: <?php $uid =
How about this:
<?php$uid = db_result(db_query('SELECT uid from {node} WHERE nid ='. $node->nid));
$result = db_query("SELECT nid, title FROM {node} WHERE type='listing' and uid = $uid");
print "<ul>";
while($obj=db_fetch_object($result)){
print '<li><a href="/node/'. $obj->nid .'">'.$obj->title.'</a></li>';
}
print "</ul>";
?>
Thank you both for your
Thank you both for your comments! I also found this podcast: http://mustardseedmedia.com/podcast/episode21 which is absolutely perfect and much simpler than querying the database. I'll play with this all when I get home today.
www.digett.com - work
www.haleystar.com - personal
Awesome! Got better results
Awesome! Got better results than I was hoping for, now users don't have to click an additional link to see all posts by a certain user, they're listed on the actual profile page. Thank you both! I kinda combined both your suggestions to come up with this:
<?php$uid = arg(1);
$result = db_query("SELECT n.title, nr.body, ct.field_website_url FROM {node} n
INNER JOIN {node_revisions} nr ON n.nid = nr.nid
INNER JOIN {content_type_listing} ct ON n.nid = ct.nid WHERE n.type='listing' and n.uid = $uid");
print "<ul>";
while($obj=db_fetch_object($result)){
print '<li><a href="/node/'. $obj->nid .'">'.$obj->title.'</a>
<br/>'.$obj->body.'<br/>'.$obj->field_website_url.'</li>';
}
print "</ul>";
?>
AND I'm not having to use the tracker module which is great because I couldn't figure out a good way to customize the output being displayed with it without hacking :) Thanks again!
www.digett.com - work
www.haleystar.com - personal
I think
I think you should use views, filtering by "node type" and adding an argument "Node: User posted or commented".
Good luck!
------------------------
Glidea - Web Agency
http://www.glidea.com