When a user who is not logged in navigates to a page that is marked private they receive a 404 error page. I'd like the page to display a kind reminder to please login to view this page.
I tried adding the following to the page loop, but a non logged in user still gets the 404 error page.
if ($post->post_status == "private" && !is_user_logged_in()) {
echo "You must be logged in to view this page.";
} else if( $post->post_status == "private" && is_user_logged_in() ) {
// Page code goes here
}