Support » Fixing WordPress » wordpress if statement trouble

  • Resolved derekbeck


    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'>";
    			echo "</div>";
    			echo "gets here 2";
Viewing 8 replies - 1 through 8 (of 8 total)
  • Emil Uzelac


    Theme Review Admin

    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>
                <?php wp_list_comments('type=pings&max_depth=<em>'); ?>
    	<?php endif; ?>

    Nope, that isn’t working either…

    Emil Uzelac


    Theme Review Admin


    <?php if ( ! empty($comments_by_type['pings']) ) {
          echo "<br><h3 id='comments'>Pingbacks:</h3>";
          echo "<div id='pings'>";
    	 echo "</div>";
    } else {
          echo '';


    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 )…


    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:

    //add-in by derek beck for
    function list_pings($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
    <?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

    i got a hint from another forum that I need to set $comment_by_type as a global variable… how do I do this?

    ok, figured out that, but still calling it globally did not fix it… ugh…

    got it… the answer was here:


    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’]) ) : ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘wordpress if statement trouble’ is closed to new replies.