Languages: English โข ํ๊ตญ์ด โข (Add your language)
์๋ํ๋ ์ค ๊ธ์ ๊ณต๊ฐํ๋ฉด, ์ด ๊ธ์ ๊ณต๊ฐ์ (๊ธฐ๋ณธ)์ผ๋ก ๋ณด์ด๊ฒ ๋๋ค. ์๋ํ๋ ์ค์์ ๊ธ์ ๊ณต๊ฐํ๊ธฐ ์ํ๋ ๊ฐ์์ฑ์ด ๊ธฐ๋ณธ์ผ๋ก ๊ณต๊ฐ๋ ์ํ์ด๋ค. ๊ธ ํธ์ง ํ๋ฉด์ ๊ณต๊ฐํ๊ธฐ ์์์ ์ค์ ์ ๋ฐ๋ฅธ๋ค.
์๋ํ๋ ์ค๋ ๊ธ์ ์ฝํ ์ธ ๊ฐ์์ฑ์ ๋ํด ๋ ๊ณต๊ฐ์ ์ธ 2๊ฐ์ ์ต์ ๋ ์ ๊ณตํ๋ค. "ํธ์ง" ๋งํฌ๋ฅผ ํด๋ฆญํ๋ฉด, ๊ฐ์์ฑ: ๊ณต๊ฐ ์์ 3๊ฐ์ ๋ผ๋์ค ๋ฒํผ์ด ํ์๋๋ค:
๊ฐ์์ฑ ํธ์ง์ด ๋๋๋ฉด, "OK" ๋ฒํผ์ ํด๋ฆญํ๋ค. ์ด์ ๊ธ์ ์๋ก์ด ์ค์ ์ด ์ ์ฉ๋ ๊ฒ์ ์ ์ ์๋ค. ์, ๊ฐ์์ฑ: ๋น๋ฐ๋ฒํธ๋ก ๋ณดํธ. ๊ธฐ์ตํ์: ์ค์ ๋ณ๊ฒฝ์ "๊ณต๊ฐํ๊ธฐ" (๋๋ ๊ธ์ด ์ด๋ฏธ ๊ณต๊ฐ๋์๋ค๋ฉด, "์ ๋ฐ์ดํธ") ๋ฒํผ์ ํด๋ฆญํด์ผ ์ ์ฉ์ด ๋๋ค.
๊ด๋ฆฌ์, ํธ์ง์ ๋๋ ๊ธ์ ์ ์๋ง์ด ๊ธ์ ๋น๋ฐ๋ฒํธ ๋๋ ๊ฐ์์ฑ ์ค์ ์ ๋ณ๊ฒฝํ ์ ์๋ค. ์ด๋ ๊ฒ ํ๊ธฐ ์ํด์๋, "๊ฐ์์ฑ: ํธ์ง" ๋งํฌ๋ฅผ ๋ค์ ์ฌ์ฉํ๋ค. ์ด ์ค์ ์ ๋ชจ๋ ๊ธ ํ๋ฉด์ ์๋ ๊ธ์ ๋น ๋ฅธ ํธ์ง ๋งํฌ์์๋ ํ ์ ์๋ค.
๊ฐ์์ฑ "ํธ์ง" ๋งํฌ(๋๋"๋น ๋ฅธ ํธ์ง")์์ ์์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ฐพ์ ์๋ ์๋ค.
๊ทธ๋ฌ๋ฏ๋ก, "My Post"๋ ์ ๋ชฉ์ ๋น๋ฐ๋ฒํธ๋ก ๋ณดํธ๋ ๊ธ์ ์๋์ ๊ฐ์ด ํ์๋๋ค:
์๋ํ๋ ์ค๋ ์ด ๋น๋ฐ๋ฒํธ๋ฅผ ๋ธ๋ผ์ฐ์ ์ฟ ํค์ ์ ์ฅํ๋ค. ๊ทธ๋ฌ๋ฏ๋ก ๋ ์๋ ๊ฐ์ ํ์ด์ง๋ฅผ ์ฌ๋ฌ ๋ฒ ๋ฐฉ๋ฌธํ์ฌ๋ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ค์ ์ ๋ ฅํ ํ์๊ฐ ์๋ค. ๋๊ตฌ๋, ์ฌ๋ฌ ๊ฐ์ ๊ธ์ด ๊ฐ์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ฌ์ฉํ์ฌ๋, ๋ ์๋ ๋ชจ๋ ๊ธ์ ์ ๊ทผํ๊ธฐ ์ํด ๊ทธ ๋น๋ฐ๋ฒํธ๋ฅผ ํ ๋ฒ๋ง ์ ๋ ฅํ๋ฉด ๋๋ค. (์๋ ๊ฒฝ๊ณ ์ฐธ์กฐ).
์๋ํ๋ ์ค๋ ํ ๋ฒ์ ํ๋์ ์ํธ๋ง์ ์ถ์ ํ๋ค. ๊ทธ๋ฌ๋ฏ๋ก, ๋ ๊ฐ์ ๊ธ์ด ๋ค๋ฅธ ๋น๋ฐ๋ฒํธ๋ฅผ ์ฌ์ฉํ๋ค๋ฉด, ๊ธ A์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ๊ณ , ๊ธ B์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ๋ค๋ ๊ฒ์, ๊ธ A(๋๋ ์ด ๋น๋ฐ๋ฒํธ๋ฅผ ๊ณต์ ํ๋ ๋ชจ๋ ๊ธ)๋ฅผ ๋ค์ ๋ฐฉ๋ฌธํ ๋ ๊ธ A์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ค์ ์ ๋ ฅํด์ผ ํ๋ค๋ ๋ป์ด๋ค.
์๋ํ๋ ์ค๋ ์ ํํ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ ๋ ๊น์ง, ์ ๊ธด ๊ธ์ ๋ณธ๋ฌธ ๋๋ ์์ฝ๋ฌธ์ ํ์ํ์ง ์๋๋ค. ๊ทธ๋ฌ๋, ๊ธ์ ์ฌ์ฉ์ ์ ์ ํ๋ ๋ฐ์ดํฐ๋ ๋ณดํธ๋์ง ์์, ์ฌ์ ํ ๋ณด์ธ๋ค. ์ฌ์ฉ์ ์ ์ ํ๋๋ฅผ ๊ฐ์ถ๊ธฐ ์ํด์๋, ์กฐ๊ฑด๋ฌธ: post_password_required์ ์ฌ์ฉํ์ฌ get_post_meta ํธ์ถ (์, single.php ๋๋ page.php์ ์๋)์ ๊ฐ์ผ๋ค. ์ด ํ๋์ ์๋ํ๋ ์ค ํจ์๋ ๊ธ์ด ๋น๋ฐ๋ฒํธ๋ฅผ ์๊ตฌํ๋์ง, ์ ํํ ๋น๋ฐ๋ฒํธ๊ฐ ์ ๋ ฅ ๋์๋์ง ๋ ๋ค ์ฒดํฌํ๋ค:
<?php
if ( ! post_password_required() ) {
// Code to fetch and print CFs, such as:
$key_1_value_1 = get_post_meta( $post->ID, 'key_1', true );
echo $key_1_value_1;
}
?>
if๋ฌธ ์์ ์๋ post_password_required ํจ์๋ ๋ชฉ๋ก์ ์ ๊ธด ๊ธ์ด ํ์๋์ง ์๊ฒ ํ๋ ๊ฒ๊ณผ ๊ฐ์, ์ฌ์ฉ์ ์ ์๋ฅผ ํ๊ธฐ์๋ ํธ๋ฆฌํ๋ค.
์๋ํ๋ ์ค ํํฐ๋ฅผ ์ฌ์ฉํ์ฌ, ๋น๋ฐ๋ฒํธ ํผ์ ๊ธฐ๋ณธ ๋ฌธ์ฅ์ ๋ณ๊ฒฝํ ์ ์๊ณ , ์ ๊ธด ๊ธ ์์ฝ๋ฌธ์ ๊ธฐ๋ณธ ๋ฌธ์ฅ์ ๋ณ๊ฒฝํ ์ ์๊ณ , ๊ธ ์์ฝ๋ฌธ์ ๋น๋ฐ๋ฒํธ ํผ์ ์ฝ์ ํ ์๋ ์๋ค. ์ด๋ ๊ฒ ํ๊ธฐ ์ํด์๋, ์๋ํ๋ ์ค ํ ๋ง์ functions.php ํ์ผ์ ๋ค์ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ค.
๋น๋ฐ๋ฒํธ ํผ์ ๋ค์์ ๊ธฐ๋ณธ ๋ฉ์์ง๋ฅผ ํ์ํ๋ค: "์ด๊ธ์ ๋น๋ฐ๊ธ์ ๋๋ค. ๊ธ์ ๋ณด๋ ค๋ฉด ์๋์ ์ํธ๋ฅผ ์ ๋ ฅํ์ธ์(This post is password protected. To view it please enter your password below):" ๋ค์ ์ฝ๋๋ ์ด ํผ์ ๋ค๋ฅธ ๋ฉ์์ง์ ๋ค๋ฅธ html ๊ตฌ์กฐ์ ํผ์ ๋ฐํํ๋ค — ์ด ์์ ์์, ์ฌ์ฉ์ ์ ์ ๋ฉ์์ง๋: "To view this password protected post, enter the password below:"์ด๋ค
<?php
function my_password_form() {
global $post;
$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
$o = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post">
' . __( "To view this protected post, enter the password below:" ) . '
<label for="' . $label . '">' . __( "Password:" ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" maxlength="20" /><input type="submit" name="Submit" value="' . esc_attr__( "Submit" ) . '" />
</form>
';
return $o;
}
add_filter( 'the_password_form', 'my_password_form' );
?>
์ฐธ๊ณ : my_password_form ํจ์๋ ๊ฐ์ ๋ฐํํด์ผ ํ๋ค: print ๋๋ echo๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค.
๋น๋ฐ๋ฒํธ ๋ณดํธ ํผ์ ๊ต์ฒดํ ๋, ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ์ฝ์ผ๋ก ์ฒ์ 20 ๋ฌธ์๋ง ์ ์ฅํ๋ฏ๋กmaxlength ๋งค๊ฐ ๋ณ์๋ 20์ผ๋ก ์ค์ ํด์ผ ํ๋ค.
์ ๊ธด ๊ธ์ด ๊ธฐ๋ณธ ์์ฝ๋ฌธ์: "์ ๊ธด ๊ธ์๋ ์์ฝ๋ฌธ์ด ์์ต๋๋ค(There is no excerpt because this is a protected post)์ด๋ค" ์๋ ์ฝ๋๋ ์ด ๋ฌธ์ฅ์ ์ฌ์ฉ์ ์ ์ — HTML ๊ฐ๋ฅํ: ๋ฌธ์ฅ์ผ๋ก ๊ต์ฒดํ ๊ฒ์ด๋ค.
<?php
function my_excerpt_protected( $excerpt ) {
if ( post_password_required() )
$excerpt = '<em>[This is password-protected.]</em>';
return $excerpt;
}
add_filter( 'the_excerpt', 'my_excerpt_protected' );
?>
"<em>[This is password-protected.]</em>"์ ์ฌ์ฉ์ ์ ์ ์ ๊ธด ๊ธ ์์ฝ๋ฌธ ๋ฉ์์ง๋ก ๊ต์ฒดํ ๊ฒ์ด๋ค.
์ ๊ธด ๊ธ์ ์์ฝ๋ฌธ์ ๋ํ ๋ค๋ฅธ ์ต์ ์ ์์ฝ๋ฌธ ๋์ ์ ๋น๋ฐ๋ฒํธ ํผ์ ํ์ํ๋ ๊ฒ์ด๋ค. ์ด ๋ฐฉ๋ฒ์ ์ธ๋ฑ์ค ๋๋ ์์นด์ด๋ธ ํ์ด์ง์์ ์ง์ ๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ๋ค. ๊ทธ๋ฐ ๋ค์, ์ ๋ชฉ ๋งํฌ๋ฅผ ํด๋ฆญํ๋ฉด, ๋ณธ๋ฌธ์ ๋ณผ ์ ์๋ค. get_the_password_form ํจ์๋ฅผ ์ฌ์ฉํ์ฌ, ์ ๊ธด ๊ธ์ ์์ฝ๋ฌธ ๋์ ๋น๋ฐ๋ฒํธ ํผ์ ํ์ํ ์ ์๋ค:
<?php
function my_excerpt_password_form( $excerpt ) {
if ( post_password_required() )
$excerpt = get_the_password_form();
return $excerpt;
}
add_filter( 'the_excerpt', 'my_excerpt_password_form' );
?>
์ด๊ฒ์ ๊ธฐ๋ณธ ์๋ํ๋ ์ค ๋น๋ฐ๋ฒํธ ํผ๊ณผ ๊ธฐ๋ณธ ๋ฉ์์ง ๋๋ ์ฌ์ฉ์ ์ ์ ๋ฉ์์ง๋ฅผ ๊ฐ์ ธ์จ๋ค. post_password_required()์ get_the_password_form() ์๋ ๋ฐฉ๋ฒ์ ๋ ์ ์ดํดํ๊ณ ์ ํ๋ค๋ฉด, wp-includes/post-template.php์์ ์ด ํจ์์ ์ ์๋ฅผ ์ฝ์ด๋ณธ๋ค.
์ด ์๋ํ๋ ์ค ์ฝ์ด(core) ํ์ผ์์, the_excerpt์ the_password_form ํํฐ ๋ฐ get_the_excerpt(), get_the_title(), get_the_content() ํจ์๋ ๋ณผ ์ ์๋ค. ์ด ํจ์๋, ๊ฐ์์ฑ ์ค์ ์ ๋ฐ๋ผ, ๊ธ์ ์ ๋ชฉ, ์์ฝ๋ฌธ๊ณผ ๋ณธ๋ฌธ์ ํ์ํ๋ ๋ฐฉ๋ฒ์ ์ ์ดํ๋ค.
๋๋ก๋, ํ ํ์ด์ง ๋๋ ์์นด์ด๋ธ ํ์ด์ง๊ณผ ๊ฐ์ ์ฌ์ดํธ์ ๋ค๋ฅธ ๊ณณ์ ์ ๊ธด ๊ธ์ ํ์๋์ง ์๊ฒ ํ๊ณ ์ถ๋ค. ํ์ด์ง ๋ฒํธ(pagination)์ ์ํฅ์ ๋ฏธ์น์ง ์์ผ๋ฉด์, ํจ์จ์ ์ผ๋ก ์ ๊ธด ๊ธ์ ๊ฐ์ถ๋ ค๋ฉด, ํ ๋ง์ functions.php์ ๋ค์ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ค:
<?php
// Filter to hide protected posts
function exclude_protected($where) {
global $wpdb;
return $where .= " AND {$wpdb->posts}.post_password = '' ";
}
// Decide where to display them
function exclude_protected_action($query) {
if( !is_single() && !is_page() && !is_admin() ) {
add_filter( 'posts_where', 'exclude_protected' );
}
}
// Action to queue the filter at the right time
add_action('pre_get_posts', 'exclude_protected_action');
?>
์ด ์ฝ๋๋ ๋ ๋ถ๋ถ์ผ๋ก ์๋ํ๋ค: ์ฒซ ๋ฒ์งธ ๋ถ๋ถ์ posts_where ํํฐ๋ฅผ ์ฌ์ฉํ์ฌ. ์๋ํ๋ ์ค๊ฐ ์คํํ๊ณ ์๋ SQL ์ฟผ๋ฆฌ์์ ์ง์ ์ ๊ธด ๊ธ์ ํจ์จ์ ์ผ๋ก ์ญ์ ํ๋ค. ๋ ๋ฒ์งธ ๋ถ๋ถ์, ๊ฐ๋ณ ๊ธ, ๊ฐ๋ณ ํ์ด์ง ๋ฐ ๊ด๋ฆฌ ํ์ด์ง๋ฅผ ์ ์ธํ, ๋ชจ๋ ํ์ด์ง์ ์ด ํํฐ๋ฅผ ์ถ๊ฐํ๋ค.
์ pre_get_posts๊ฐ ์ด ํจ์์ ๋ง๋ action์ธ์ง ๋ ์์ธํ ์์๋ณด๋ ค๋ฉด, pre_get_posts action reference๋ฅผ ์ฐธ์กฐํ๋ค.