homepage Welcome to WebmasterWorld Guest from 174.129.130.202
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Content Management
Forum Library, Charter, Moderators: ergophobe

Content Management Forum

    
Need to Grab Comments from another Page
Grabbing Comments
ianternet




msg:3879694
 10:22 pm on Mar 26, 2009 (gmt 0)

I want to add the comments of another page post from wordpress to a separate page. I do not want to show the comment form tho, just the comments from one post.

what I am doing is collecting comments in one page, without displaying it and I want to display those comments on another wordpress page.

is this possible? I can collect the comments but cant seem to display it on another pose/page

any advice is appreciated.

 

ergophobe




msg:3880171
 3:42 pm on Mar 27, 2009 (gmt 0)

Hmm... when I see questions like this, I always wonder what the "why" is and if there wouldn't be a completely different approach that would make more sense.

Just to be clear, you literally mean that you have a page about topic A and you want the comments to show up somewhere else entirely, not associated with that page? Or do you simply want the content page to be free of comments on first view and the comments only appear when someone clicks to see comments? I'm reading this as asking the first question. So....

There may be some API for doing it, but I don't know Wordpress internals well enough (now if it were Drupal...).

Essentially, though, WP has a function in /wp-include/comments.php called get_approved_comments() that is a simple wrapper for a DB request, like so

function get_approved_comments($post_id) {
global $wpdb;

$post_id = (int) $post_id;
return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1' ORDER BY comment_date");
}

So basically, you would need to feed that the id of the page where the comments were actually made and then output and format that information on the page you're viewing. This would probably have to be a hard-coded relationship, meaning you would have to put in the specific post id every time you wanted to do this.

If you wanted this somehow automated, you would need to build a new database table that would establish relationships between pages.

ianternet




msg:3883574
 12:14 am on Apr 2, 2009 (gmt 0)

"Just to be clear, you literally mean that you have a page about topic A and you want the comments to show up somewhere else entirely, not associated with that page? Or do you simply want the content page to be free of comments on first view and the comments only appear when someone clicks to see comments? I'm reading this as asking the first question. So.... "

I have a page (page a) where I collect the comments and do not display the comments on that one page. but I would like the comments on another page to show from page A onto a new page (page b)

I want to be able to say "if this is page id B then show comment from page A" else no comments

ergophobe




msg:3883664
 4:57 am on Apr 2, 2009 (gmt 0)

Okay, so then the code above should do it. So you would need integrate that into your theme so that on page B you make a call to get_approved_comments() and feed it the id of page A.

I'm still trying to think of where I would want to do that....

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Content Management
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved