Can comments of a particular content type be listed in a page with the user name and page where the comment was posted? Is there a module out there which can do this work?

Comments

WorldFallz’s picture

You should be able to do with with http://drupal.org/project/views. Set the view to filter for the content type you want, set another filter to be for number of comments greater than "0", and set the fields to be comment author, node title, and whatever else you want.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

himagarwal’s picture

Thanks again. I think now it's time for me to start learning views, panels, CCK and taxanomy. I think it will at least take a week.........

meanwhile I used comments_page module which I chagned according to my need

<?php 
// $Id: comments_page.module,v 1.1 2007/10/28 11:37:57 mjmalloy Exp $
	
/** 
 * Implementation of hook_menu(). 
 */ 
function comments_page_menu($may_cache) { 
	global $user;
	$items = array(); 

  if (!$may_cache) { 
	$items[] = array(
	  'path' => 'comments',
	  'title' => t('Comments'),
      'callback' => 'comments_page',
      'access' => user_access('access comments'),
      'type' => MENU_SUGGESTED_ITEM
	);
  }
  
  return $items; 
}

/**
 * Menu callback; displays a Drupal page containing recent comments.
 */
function comments_page($a = NULL, $b = NULL) {
	if (!user_access('access comments') )
	{
		return drupal_access_denied();
	}
	if (is_numeric($a)) { // $a is a user ID
		return comments_page_user($a);
	}
	else {
		return comments_page_last();
	}
}

/**
 * Displays a Drupal page containing recent comments of all users.
 */
function comments_page_last() {
	global $user;
	$output = '';
	$result = pager_query(db_rewrite_sql("SELECT c.comment, c.cid, c.nid, c.uid, c.timestamp, n.title, u.name FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid INNER JOIN {users} u ON c.uid = u.uid WHERE n.status = 1 ORDER BY c.timestamp DESC"), variable_get('default_nodes_main', 1000));
	while ($comment = db_fetch_object($result)) {
		$output .= '<div class="node">';
		$output .= '<div class="node-content">';
		$output .= '<div class="content">';
		
		$output .= '<div class="usercomment">'.check_markup($comment->comment).'</div>';
		
		$output .= '<div class="datesetting">';
		$output .= ' posted by ';
		$output .= '<span class="node-author node-content-top">'.check_plain($comment->name).'</span>';
		$output .= ' on ';
		$output .= '<span class="node-date node-content-top">'.format_date($comment->timestamp, 'custom', "F jS, Y").'</span>';
		$output .= ' in ';
		$output .= '<span class="title">'.l($comment->title, "node/".$comment->nid, array('title' => $comment->title)).'</span>';
		$output .= '</div>';
		
		$output .= '</div>';
		$output .= '</div>';
		$output .= '</div>';
	}
	$output .= theme('pager', NULL, variable_get('default_nodes_main', 1000));
	return $output;
}

I have created a conteny type called "product" and I only want to show comments from "product". Is there a way to add this in this module?

WorldFallz’s picture

I'm no developer, but I think you could either add some SQL to the query (with something like WHERE n.type = '[your-content-type]') but i'm not sure exactly where in such a complex query.

Alternatively, you could enclose all the code in your while loop in an if conditional that tests for $node->type='[your-content-type]'. My only concern there, is that you will have to do a load node for each node id to test this condition-- depending on the size of $result, I would imagine that could be quite costly.

I'm totally guessing, but I would think doing it in the SQL has to be better performance wise.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

himagarwal’s picture

thanks.....tried adding n.type to the sql but don't know where to add.....anyways tried few places where I think it might work but it didn't. hope some help comes out.........

WorldFallz’s picture

After looking at the query again, i would think you need to change " WHERE n.status = 1 ORDER BY" to " WHERE n.status = 1 AND n.type = '[content-type]' ORDER BY"-- did you try that one?

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

himagarwal’s picture

Dude, you are awesome. You are not less than a programmer........
It worked liked a charm.....thank you very much........
Well, not currently required but in case if I need to add more than one content type, is it possible?

*&$(#_(*%

WorldFallz’s picture

lol, not hardly-- just an educated guess but you're very welcome. glad it worked.

and yes, you should be able to add as many content types as you want-- I think you just need to add "OR n.type = '[content-type]'" for each additional content type you want to add.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

himagarwal’s picture

thanks........one problem sorted out....severals to go but before I'll sit back for couple of days to learn cck+views.

himagarwal’s picture

I did it with views as WorldFallz said. Though only I know basics currently, it was very very simple to set up. I wished I knew views earlier.

How can I change the theme (css) of the views I've created? Is admin/build/views/wizard is the only option?

And, is there any advanced video tutorial on cck, taxonomy, views and panels?

Thanks.

WorldFallz’s picture

That's awesome! Unfortunately, theming views isn't quite as easy as creating them, lol. There's some AWESOME videos on theming views as well as the using all the modules you mention over at http://drupaldojo.com-- unfortunately, the site's be down the better part of a week. IIRC, some of them are stored over at blip.tv-- you can probably find them searching with "drupal". Otherwise, just keep checking until the site is back up. I would browse all the videos there-- they're all good and they cover most must-know drupal topics. You can find some other good video repositories at Videos and slides.

And here's some links i found useful:

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

himagarwal’s picture

Thanks.

Is using Views Wizard a good option though I have to create .phptemplate, .tpl and .css file for every single view?

WorldFallz’s picture

If you want to change the structure yes-- and the first link above uses the views theming wizard. However, as with anything else on the web, if you just want to change appearance (and not structure), you can do some theming just with css.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz