I am using the_content filter to append comment summaries to posts on a blog page. That part of my code works. I am having a problem with the display of pages where they are not formatted and shortcodes are not rendered. What am I missing, or doing wrong?
function display_comment_summaries() {
$p = get_post();
$output = '';
$output .= $p->post_content;
if ( is_front_page() && is_home() ) {
// Default homepage
return;
} elseif ( is_front_page() ) {
// static homepage
goto display_output;
} elseif ( is_home() ) {
// blog page
goto display_comments;
} else {
//everything else
goto display_output;
}
display_comments:
$num_comments = 5;
if (( $p->comment_count ) > 0) {
$output .= '<p style="font-weight: 700; margin-top: 10px;">Latest Comments (' . $p->comment_count . ')</p>';
$output .= '<ul style="list-style-type: none; margin-bottom: 10px; padding-left: 0;">';
$comments = get_comments( array ( 'post_id' => $p->ID ) );
if (($p->comment_count) < $num_comments) {
$num_comments = $p->comment_count;
}
$i = 0;
foreach ( $comments as $c ) {
if ($i < $num_comments) {
$day = ltrim( substr( $c->comment_date, 8, 2 ), '0' );
$year = substr( $c->comment_date, 0, 4 );
$month_name = date( "F", strtotime( substr( $c->comment_date, 0, 10 ) ) );
$date = $month_name . ' ' . $day . ', ' . $year;
$output .= '<li>' . $c->comment_author . ' on ' . $date . '</li>';
$i++;
}
}
$output .= '</ul>';
$output .= '<p><a href="' . get_permalink( $p->ID ) . '#comments' . '">'
. 'Read Comments</a></p>';
}
display_output:
echo $output;
}
the_content()
orget_the_content()
, which would actually pull in the post content. ($post->post_content
is the raw post content, before thethe_content
filter gets applied.) 2. Is there a compelling reason for you to usegoto
instead of functions?