admin管理员组文章数量:1125966
I want private posts (for those not logged in) to use the single.php
template just as public posts do, at the moment they get thrown over to the 404.php
template.
I've had a good look through the core files but I cannot find where the template change (note: this is not a redirect) happens.
Can anyone help?
Edit
To explain why I want this, I want all visitors to see a preview of the content, but logged in "members" to see the entire post content.
I want private posts (for those not logged in) to use the single.php
template just as public posts do, at the moment they get thrown over to the 404.php
template.
I've had a good look through the core files but I cannot find where the template change (note: this is not a redirect) happens.
Can anyone help?
Edit
To explain why I want this, I want all visitors to see a preview of the content, but logged in "members" to see the entire post content.
Share Improve this question edited Jun 5, 2013 at 14:54 Ben Everard asked Jun 5, 2013 at 14:07 Ben EverardBen Everard 1,2785 gold badges19 silver badges33 bronze badges 2 |3 Answers
Reset to default 2According to the Content Visibility page, Private posts are visible only to those with sufficient permission levels. WordPress doesn't expose them to non-logged-in users at all, hence (presumably) the 404
.
If you want to display a limited preview to non-members, instead of setting the post to Private, you could try something like this:
add_filter( 'the_content', 'wpse101968_preview' );
function wpse101968_preview( $content ) {
if( is_single() ) {
if( ! is_user_logged_in() ) {
$content = get_the_excerpt();
}
}
return $content;
}
And then your non-logged-in visitors will see the post's excerpt instead of the entire post. You can customize the excerpts, too, so that they see only what you want them to see.
References
Codex:
is_user_logged_in()
get_the_excerpt()
You are not seeing a redirect, to confirm your own observation, so much as you are seeing just what it looks like-- a "File Not Found". Take a look at the query in the source around line 2438 (among others). The status of the post is part of the query itself, so if the status doesn't match then no posts are found and that means 404
. As you can see from the code, status
is pretty rigidly protected. That is proving difficult to override.
I'd recommend using a custom post type for you "logged in only" posts. That is going to be much easier to control both on the front end and the back end.
How do you set password protected posts to be viewed by logged-out users? We created the functionality and all logged-out users are getting a 404 after inserting the password.
本文标签: templatesPrevent private post 404
版权声明:本文标题:templates - Prevent private post 404 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736629604a1945748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
404
theme load is coming from somewhere other than WP core? – Pat J Commented Jun 5, 2013 at 14:33single.php
template. – Ben Everard Commented Jun 5, 2013 at 14:37