derekbeck
Member
Posted 1 year ago #
In my comments.php, I'm trying to list my pingbacks separate. If I remove the if statement (and endif) around the code below, the pages with pingbacks do indeed list the pingbacks. However, I don't want my h3 title to appear unless there are indeed pingbacks to display, so I built the following if statement around the pingback-generating code.
I can't figure this out: the code does not get in my if statement. It just ignores that section. Any ideas why?
echo "gets here 1";
if ( ! empty($comments_by_type['pings']) ) : //only placed in if there are indeed pingbacks
echo "does not get inside";
echo "<BR><h3 id='comments'>Pingbacks:</h3>";
echo "<div id='pings'>";
wp_list_comments('type=pings&callback=list_pings');
echo "</div>";
endif;
echo "gets here 2";
How about this?
<?php if ( ! empty($comments_by_type['pings']) ) :
$count = count($comments_by_type['pings']);
($count !== 1) ? $txt = "Pings/Trackbacks" : $txt = "Pings/Trackbacks"; ?>
<h3 id="pings"><?php echo $count . " " . $txt; ?> for "<?php the_title(); ?>"</h3>
<ul>
<?php wp_list_comments('type=pings&max_depth=<em>'); ?>
</ul>
<?php endif; ?>
derekbeck
Member
Posted 1 year ago #
Nope, that isn't working either...
Try:
<?php if ( ! empty($comments_by_type['pings']) ) {
echo "<br><h3 id='comments'>Pingbacks:</h3>";
echo "<div id='pings'>";
wp_list_comments('type=pings&callback=list_pings');
echo "</div>";
} else {
echo '';
}
?>
derekbeck
Member
Posted 1 year ago #
Emil,
Thanks for your replies!
Unfortunately, no, that doesn't work either. For that last echo ''; in the else I put in "inside" and it gets into the else.
This means that for some reason the ! empty($comments_by_type['pings']) statement fails. I wonder if I don't have the variable $comments_by_type or the function "empty" or something? Any idea how to test for this to narrow it down?
I am using WP 3.0.4 but I wonder if it is some kind of flaw in the theme I'm using ( Atahualpa 3.5.3 which is very complex and is touted as the most customizable theme available )...
derek
derekbeck
Member
Posted 1 year ago #
ok, convinced the comments_by_type is the problem... (I'm following this example.)
I have in my functions.php the following which declares comments_by_type per the example linked, but I think it is flawed:
<?php
//add-in by derek beck for
//from www.wphacks.com/separating-trackbacks-from-comments-in-wordpress-2-7/
function list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
<?php } ?>
<?php
add_filter('get_comments_number', 'comment_count', 0);
function comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;
}
}
//end add-in
?>
derekbeck
Member
Posted 1 year ago #
i got a hint from another forum that I need to set $comment_by_type as a global variable... how do I do this?
derekbeck
Member
Posted 1 year ago #
ok, figured out that, but still calling it globally did not fix it... ugh...
derekbeck
Member
Posted 1 year ago #
got it... the answer was here: http://wordpress.org/support/topic/comments_by_type-problems
answer:
Try adding the this
<?php $comments_by_type = &separate_comments($comments); ?>
directly before
<?php if ( !empty($comments_by_type['comment']) ) : ?>
This worked for me except I am using
<?php if ( !empty($comments_by_type['pings']) ) : ?>
instead of
<?php if ( !empty($comments_by_type['comment']) ) : ?>