我正在将此自定义代码用于我的循环。php文件,用于限制未注册成员访问特定类别的帖子(cat 1)
<?php if (is_user_logged_in() && $cat == \'1\') { ?>
<?php the_content(); ?>
<?php } else { ?>
<?php the_excerpt(); ?>
<?php } ?>
然而,这段代码没有多大帮助,因为它也限制了其他类别的所有帖子。有什么建议吗?
我正在将此自定义代码用于我的循环。php文件,用于限制未注册成员访问特定类别的帖子(cat 1)
<?php if (is_user_logged_in() && $cat == \'1\') { ?>
<?php the_content(); ?>
<?php } else { ?>
<?php the_excerpt(); ?>
<?php } ?>
然而,这段代码没有多大帮助,因为它也限制了其他类别的所有帖子。有什么建议吗?
尝试以下操作:
<?php
//first check if its the category in question
if ($cat == \'1\') {
//then if the user is logged in show the content
if (is_user_logged_in()){
the_content();
}else{ //if not show the excerpt
the_excerpt();
}
}else{ // and if its not the category show the content
the_content();
}
?>
更新从你的评论来看$cat
在检查so之前添加:$cat = get_query_var(\'cat\');
在条件代码之前。