doumu5662 2016-09-24 00:54
浏览 10
已采纳

wordpress得到最近的评论

I have been tryin for the last few hours to research how to get recent comments from wordpress. here is how I managed to get recent posts....

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

how do I get the latest comments..

ps. I have tried to change the posts to comments and doesn't work.

Thanks in advance

Steven

  • 写回答

1条回答 默认 最新

  • dtng25909 2016-09-24 02:03
    关注

    You can retrieve recent comments using get_comments().

    get_comments() works in a very similar way to the function you're using to retrieve posts.

    <?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>';
    
        }
    } 
    

    Further reading: https://codex.wordpress.org/Function_Reference/get_comments

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起