开发者

Wordpress Post - password protected & excerpt

开发者 https://www.devze.com 2023-02-27 03:32 出处:网络
am newbie in wordpress.. I have installed its version 3.1.1.. I just want to know how can开发者_StackOverflow中文版 I make the post password protected

am newbie in wordpress.. I have installed its version 3.1.1..

I just want to know how can开发者_StackOverflow中文版 I make the post password protected and how to add excerpt for it....?


Assuming you mean WordPress 3.1.1, then the answer is that on the page where you author a post there is a place to enter an excerpt. You can read more in the WordPress codex here: http://codex.wordpress.org/Excerpt

Regarding password protection, you can make a post password protected or private (different things). In a standard WP installation there is a "Publish" panel near the top right of the page that controls this. Here is the documentation: http://codex.wordpress.org/Content_Visibility

More sophisticated password protection options are available via plugins.


I was looking for a solution to make the excerpt available in a password protected post and I've found only this old / not working way, so I made my own by adding this code to your theme functions.php

function gettext_pp( $translation, $text ) {
    if ( $text == 'There is no excerpt because this is a protected post.' ) {
        $post = get_post();
        $translation = $post->post_excerpt;
    }
    return $translation;
}
add_filter( 'gettext', 'gettext_pp', 10, 2 );

this way you are bypassing the filter "get_the_excerpt" that it's not used applied in case the post is password protected.

If you also need to display the excerpt before the content you can do this:

function excerpt_before_pf( $output ) {
    $post = get_post();
    return $post->post_excerpt . $output;
}
add_filter( 'the_password_form', 'excerpt_before_pf' );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号