Не получается определить массив
Не могу вставить и определить массив.
} 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>';
}
?>
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 )) ... и тд }не совсем понял куда
<?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>'; } ?><?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>'; } } ?>Перестает комментарии выведывать у кого есть, а у кого нет просто не выводит echo 'Комментариев нет';
код немного поправил - ($comments_count)
проверьте что у вас в переменных и в ID пользователей лежит
$us_id
$user_id
$_GET['uid']
вроде $args = array( 'user_id' => $_GET['uid'], 'count' => true );
но он количество комментариев показывает где они есть, а там где комментов нет пусто
Если тут ставлю
if ( (int) $comments_count < 3 ) {тогда начинает выводит к Комментариев нет
у пользователей у которых нет комментариев не выводит.
Пробывал ставить 0 и -1
даже так не пашет
Упростил код. Но у кого нет Комментов, не выводит:
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>'; }}сделал