按登录用户显示帖子数

时间:2015-11-02 作者:Demilio

如何显示登录用户写入的帖子数。

这是我从抄本上得到的

<?php echo \'Number of posts published by user: \' . count_user_posts( 5 ); ?>

1 个回复
最合适的回答,由SO网友:Tobias Beuving 整理而成

下面是一个代码示例,注释中有解释:

// First a check whether the use is logged in or not:
if ( is_user_logged_in() ) {
   // The user is logged, retrieve the user id
    $user_ID = get_current_user_id(); 
   // Now we have got the user\'s id, we can pass it to the function \'count_user_posts\':
    echo \'Number of posts published by user: \' . count_user_posts( $user_ID );
} else {
    //  The user is not logged in
}