WordPress как на ладони
Очень Удобный и Быстрый Хостинг для сайтов на WordPress. Пользуюсь сам и вам рекомендую!

Не получается определить массив

Не могу вставить и определить массив.

} else {
  echo '<ol><pre>Комментариев нет</pre></ol>';

тут

  <?php
  if ( is_user_logged_in() ) { $user_id = get_current_user_id(); }
  $args = array('user_id' => $_GET['uid'] ); if( $comments = get_comments( $args )){

	echo '<ol>';
	foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID ); $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 150 ) .'...';
	  echo '<li>'. '<span class="color-pf-green">' . $comment->post_title .' :</span>'.'<pre><i class="fa fa-comments-o color-pf-ser"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
	}
	echo '</ol>';

} else {  // Профиль авторизованного

   $args = array( 'user_id' => $us_id ); if( $comments = get_comments( $args ))

	   echo '<ol>';
	  foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID );$comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 150 ) .'...';
		echo '<li>'. '<span class="color-pf-green">' . $comment->post_title .' :</span>'.'<pre><i class="fa fa-comments-o color-pf-ser"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
	  }
	  echo '</ol>';
  }

   ?>
0
pfilan
2.4 года назад 24
  • 1
    kolshix779 paxtoy.com

    https://wp-kama.ru/function/get_comments#count
    4 Выведем количество комментариев пользователя.

    } else {  // Профиль авторизованного
    
    		$args = array(
    			'user_id' => 1,
    			'count'   => true
    		);
    		$comments = get_comments( $args );
    		echo $comments
    
    		} elseif ( (int) $comments < 1 ) {
    			echo 'Комментариев нет';
    		} else {
    			 $args = array( 'user_id' => $us_id ); if( $comments = get_comments( $args ))       ... и тд 
    
    		}
    pfilan 2.4 года назад

    не совсем понял куда

      <?php
      if ( is_user_logged_in() ) { $user_id = get_current_user_id(); }
      $args = array('user_id' => $_GET['uid'] ); if( $comments = get_comments( $args )){ // Профиль не авторизованного
    
    	echo '<ol>';
    	foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID ); $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 150 ) .'...';
    	  echo '<li>'. '<span class="color-pf-green">' . $comment->post_title .' :</span>'.'<pre><i class="fa fa-comments-o color-pf-ser"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
    	}
    	echo '</ol>';
    
    } else {  
    
       $args = array( 'user_id' => $us_id ); if( $comments = get_comments( $args )) // Профиль авторизованного
    
    	   echo '<ol>';
    	  foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID );$comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 150 ) .'...';
    		echo '<li>'. '<span class="color-pf-green">' . $comment->post_title .' :</span>'.'<pre><i class="fa fa-comments-o color-pf-ser"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
    	  }
    	  echo '</ol>';
      }
    
       ?>
    kolshix 2.4 года назад
    <?php
    	if ( is_user_logged_in() ) {    $user_id = get_current_user_id(); }
    
    	$args = array('user_id' => $_GET['uid'] ); 
    	if( $comments = get_comments( $args )){         
    		// проверка количества 
    		$args_count = array(    'user_id' => $user_id,  'count'   => true   );
    		// или 
    		// $args = array(   'user_id' => $_GET['uid'],  'count'   => true   );
    		$comments_count = get_comments( $args_count );      
    		// посмотреть что в переменной лежит
    		echo $comments_count ;
    		if ( (int) $comments_count < 1 ) {
    			echo 'Комментариев нет';
    		} else {                        
    			echo '<ol>';
    				foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID ); $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 150 ) .'...';
    					  echo '<li>'. '<span class="color-pf-green">' . $comment->post_title .' :</span>'.'<pre><i class="fa fa-comments-o color-pf-ser"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
    				}
    			echo '</ol>';
    		}
    	} else {  // Профиль авторизованного
    		$args = array( 'user_id' => $us_id ); 
    		if( $comments = get_comments( $args )){
    			echo '<ol>';
    				foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID );$comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 150 ) .'...';
    					echo '<li>'. '<span class="color-pf-green">' . $comment->post_title .' :</span>'.'<pre><i class="fa fa-comments-o color-pf-ser"></i> <a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
    				}
    			echo '</ol>';
    		}
      }
    
       ?>
    
    pfilan 2.4 года назад

    Перестает комментарии выведывать у кого есть, а у кого нет просто не выводит echo 'Комментариев нет';

    kolshix 2.4 года назад

    код немного поправил - ($comments_count)
    проверьте что у вас в переменных и в ID пользователей лежит
    $us_id
    $user_id
    $_GET['uid']

    pfilan 2.4 года назад

    вроде $args = array( 'user_id' => $_GET['uid'], 'count' => true );

    но он количество комментариев показывает где они есть, а там где комментов нет пусто sad

    pfilan 2.4 года назад

    Если тут ставлю

    if ( (int) $comments_count < 3 ) {

    тогда начинает выводит к Комментариев нет

    у пользователей у которых нет комментариев не выводит.
    Пробывал ставить 0 и -1

    pfilan 2.4 года назад

    даже так не пашет

      if ( (int) $comments_count = 0 )
    pfilan 2.3 года назад

    Упростил код. Но у кого нет Комментов, не выводит:

    echo '<ol><pre>Комментариев нет</pre></ol>';
     if ( is_user_logged_in() ) { $user_id = get_current_user_id(); }
    
    	  $args = array('user_id' => $author->ID );
    	  if( $comments = get_comments( $args )){
    		// проверка количества
    		$args_count = array('user_id' => $author->ID,  'count'   => true   );
    		$comments_count = get_comments( $args_count );
    		// посмотреть что в переменной лежит
    		echo $comments_count ;
    		if ( (int) $comments_count < 1 ) {
    		  echo '<ol><pre>Комментариев нет</pre></ol>';
    		} else {
    		  echo '<ol>';
    	   foreach( $comments as $comment ){ $comm_link = get_comment_link( $comment->comment_ID ); $comm_short_txt = mb_substr( strip_tags( $comment->comment_content ), 0, 120 ) .'...';
    		 echo '<li><pre>' . $comment->post_title .':</span><br/><br/>';
    	   echo '<a rel="nofollow" href="'. $comm_link .'">'. $comm_short_txt .'</a></pre></li>';
    	   }
    	   echo '</ol>';
       }}
    pfilan 2.3 года назад

    сделал

    Комментировать
На вопросы могут отвечать только зарегистрированные пользователи. Вход . Регистрация