我正在使用WordPress 3.5,我的博客站点有许多注册用户。登录后,我希望他们只看到自己的帖子,而不是其他帖子。
所以我在我的functions.php
, 但我得到了一张空白页。
function only_login_user_post_on_homepage() {
$current_user = wp_get_current_user();
query_posts(\'author=\', $current_user -> ID);
}
add_action( \'pre_get_posts\', \'only_login_user_post_on_homepage\' );
因此,我对add_action
, 然后转到index.php
, 添加相同的代码:$current_user = wp_get_current_user();
query_posts("author=".$current_user -> ID);
是的,有结果了,我不知道为什么?代码是一样的,但为什么我得到了不同的结果。