Title: wordpress if statement trouble
Last modified: August 19, 2016

---

# wordpress if statement trouble

 *  Resolved [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/)
 * 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";
       ```
   

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Emil Uzelac](https://wordpress.org/support/users/emiluzelac/)
 * (@emiluzelac)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862157)
 * 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; ?>
       ```
   
 *  Thread Starter [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862161)
 * Nope, that isn’t working either…
 *  [Emil Uzelac](https://wordpress.org/support/users/emiluzelac/)
 * (@emiluzelac)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862163)
 * 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 '';
       }
       ?>
       ```
   
 *  Thread Starter [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862413)
 * 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
 *  Thread Starter [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862426)
 * ok, convinced the comments_by_type is the problem… ([I’m following this example](http://wphacks.com/separating-trackbacks-from-comments-in-wordpress-2-7/).)
 * 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
       ?>
       ```
   
 *  Thread Starter [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862486)
 * i got a hint from another forum that I need to set $comment_by_type as a global
   variable… how do I do this?
 *  Thread Starter [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862496)
 * ok, figured out that, but still calling it globally did not fix it… ugh…
 *  Thread Starter [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * (@derekbeck)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862506)
 * got it… the answer was here: [http://wordpress.org/support/topic/comments_by_type-problems](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’]) ):?
   > >

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘wordpress if statement trouble’ is closed to new replies.

## Tags

 * [pingbacks](https://wordpress.org/support/topic-tag/pingbacks/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [derekbeck](https://wordpress.org/support/users/derekbeck/)
 * Last activity: [15 years, 4 months ago](https://wordpress.org/support/topic/wordpress-if-statement-trouble/#post-1862506)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
