我使用页面模板显示自定义帖子类型。
自定义帖子类型中的所有内容都应受到密码保护。我想使用wordpress编辑器获取一些额外的公共信息。我可以排除吗the_content();
来自wordpress密码保护?
页面我的自定义帖子类型。php
// ================ PUBLIC AREA BEGINNS ================
<h4>Pubic-Area</h4>
<?php
if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile;
endif;
// ================ PUBLIC AREA ENDS ================
// ================ PROTECTED AREA BEGINNS ================
if ( post_password_required() ) {
echo get_the_password_form();
}
else {
$index = \'A\';
$terms = get_terms(\'marke\');
foreach ($terms as $term) {
if($index != strtoupper(substr($term->name, 0, 1))) {
$index = strtoupper(substr($term->name, 0, 1));
echo \'<h1>\'. $index . \'</h1>\';
}
?>
<h2><?php echo $term->name; ?></h2>
<?php $args = array( \'post_type\' => \'cpt_auto\', \'posts_per_page\' => -1, \'orderby\' => \'title\', \'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'marke\',
\'field\' => \'slug\',
\'terms\' => array($term->slug)
)
)
);
// ============================= OUTPUT ==============================
$loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();
the_title(\'<h3>\', \'</h3>\');
the_content();
endwhile;
}
?>
<?php }
// ================ PROTECTED AREA ENDS ================
?>
谢谢Sogni
SO网友:bueltge
可以使用条件标记if ( post_password_required() ) :
用于检查,如果需要密码,则排除the_content()
.
// view content, only if password is required
if ( post_password_required() )
the_content();
此外,您还可以使用全局var
$post
if ( ! empty( $post->post_password ) ) :
Ot,最后一次机会,也不是很好,但有用的是增强查询:
AND post_password = \'\'