Private属性文章无法显示

Posted on 2005-03-18 20:37  freshventure  阅读(469)  评论(0编辑  收藏  举报

Show private entries when logged in

http://wiki.cornbreadtree.org/index.php?title=How_do_I_set_up_Wordpress_on_cornbreadtree.org%3F#Show_private_entries_when_logged_in
I have no idea why this bug hasn't been fixed in the Wordpress 1.5 codebase, but $user_ID never seems to be set properly when PHP goes to the database. Call get_currentuserinfo() immediately before to ensure all the posts are retreived.

wp-includes/classes.php:

get_currentuserinfo();
// Get private posts
if (isset($user_ID) && ('' != intval($user_ID)))
    $where .= " OR post_author = $user_ID AND post_status != 'draft' AND post_status != 'static')";
else
    $where .= ')';

Once all the posts are loaded (when the owner is logged in, of course), distinguish between private and published posts with the following hack:

wp-includes/template-functions-post.php:

function get_the_title($id = 0) {
    global $post, $wpdb;

    if ( 0 != $id ) {
        $id_post = $wpdb->get_row("SELECT post_title, post_password FROM $wpdb->posts WHERE ID = $id");
        $title = $id_post->post_title;
        if (!empty($id_post->post_password))
            $title = sprintf(__('Protected: %s'), $title);
        }
        else {
            $title = $post->post_title;
            if (!empty($post->post_password))
                $title = sprintf(__('Protected: %s'), $title);
        }
        if ($post->post_status == "private") {  

$title = sprintf(__('Private: %s'), $title);
}
return $title; }