0

I'm trying to setup a page and extract comments from an external post. I took this advice how to pull wordpress post comments to a external page and now I have this get_comments code at my disposal:

<?php 
$comments = get_comments('post_id=15');
    foreach($comments as $comment) :
    echo($comment->comment_author);
endforeach;
?>

Where on the page do I place this? Sorry for the noob question!

  • Well, where do you want comments to appear? How are you setting up page - custom page template? – Rarst Nov 10 '11 at 12:40
  • Yes custom template and I can say that I've progressed since last week. Thanks for replying. – AlxVallejo Nov 17 '11 at 20:12
  • if you solved this by yourself please post this as an answer so others can benefit from it. If not (for any reason) and you no longer need answer to this specific question we can close it. – Rarst Nov 17 '11 at 20:39
0

I would rarely use 'echo' in WordPress template themes because it can cause output to appear before the loops are even executed (aka, at the top of the page).

In this instance, I used the get_comments function within a function that hooked onto the content output:

add_filter('the_content', 'includePosts', 1);

Within the function includePosts, I have set $Comments to appear in the $content variable and I return $content just before adding the filter.

$content is used within the wp core function 'the_content' (includes/wp-page-template).

function the_content($more_link_text = null, $stripteaser = 0) {
$content = get_the_content($more_link_text, $stripteaser);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]&gt;', $content);
echo $content;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.