Welcome to WebmasterWorld Guest from 50.19.156.133

Forum Moderators: ergophobe

Message Too Old, No Replies

Need to Grab Comments from another Page

Grabbing Comments

     

ianternet

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

5+ Year Member



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

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

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

5+ Year Member



"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

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

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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....

 

Featured Threads

Hot Threads This Week

Hot Threads This Month