2016-09-24 2 views
0

나는 지난 몇 시간 동안 wordpress에서 최근 코멘트를 얻는 방법을 연구하기 위해 노력하고 있습니다. 여기가 .... 내가 최근 게시물을 얻을 수 있었다 어떻게 최신 의견을 얻을 어떻게 wordpress 최근 코멘트를 얻으십시오

<h4>Recent Posts</h4> 
    <ul> 
     <?php 
      $args = array('numberposts' => '5'); 
      $recent_posts = wp_get_recent_posts($args); 
      foreach($recent_posts as $recent){ 
       echo '<li><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"].'</a> </li> '; 
      } 
      wp_reset_query(); 
     ?> 
    </ul> 

..

PS입니다. 게시물을 댓글로 변경하려고 시도했지만 작동하지 않습니다. 사전

스티븐

+0

이 (워드 프레스에 기본적으로 존재하는) : http://www.wpbeginner.com/beginners-guide/how-to-show -recent-comments-in-wordpress-sidebar/ – mimarcel

+0

나는 할 수 있음을 알고 있지만, 코드를 배울 것이지만 ... 감사합니다. – scottiescotsman

답변

0

에서

덕분에 당신은 get_comments()를 사용하여 최근의 주석을 검색 할 수 있습니다.

get_comments()은 게시물을 검색하는 데 사용하는 기능과 매우 유사합니다.

<?php $recent_comments = get_comments(array( 
    'number'  => 5, // number of comments to retrieve. 
    'status'  => 'approve', // we only want approved comments. 
    'post_status' => 'publish' // limit to published comments. 
)); 

if ($recent_comments) { 
    foreach ((array) $recent_comments as $comment) { 

     // sample output - do something useful here 
     echo '<a href="' . esc_url(get_comment_link($comment)) . '">' . get_the_title($comment->comment_post_ID) . '</a>'; 

    } 
} 

추가 읽기 : 당신을위한 위젯을 사용할 수 있습니다 https://codex.wordpress.org/Function_Reference/get_comments

관련 문제