Hi I am adding a link to user's blogs in various places (custom profiles, forum posts, etc) .. I don't have a problem creating the link.

What I want to do is only display the link for users who have made at least one blog entry. This way there aren't links to empty user blogs.

How can I test to see if a user has created at least one blog entry?

Code snippets much appreciated.

Comments

thepaul’s picture

Figured it out:

<?php
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $thisuser->uid);

if ( db_num_rows($result) > 0 ) {
print("<a href=\"/members/".$thisuser->name."/blog\">".$thisuser->name."'s Blog</a>");
}
else {
}
?>

important to note that $thisuser is the user object of the person who's profile or forum post you are looking at.

And the path to user blogs on my site is /members/username/blog

Also just copied the query from somewhere else so it isn't optimized for this task.