是的,这是可能的。
基本上,您需要为视频显示的任何帖子类型创建主题模板。(如果是页面,请创建页面模板;如果是自定义帖子类型,请为该帖子类型创建模板)。根据插件的不同,您需要计算出具体的查询和代码,但基本上:
<?php
// First check if the user is logged in
if(is_user_logged_in()) {
// If they\'re logged in, show the sitewide header
get_header();
// If they\'re logged in, have they bought this particular product?
// First identify the product ID
// Then check if they\'ve bought that product,
// and save to a variable called $user_has_purchased
// Then, add conditions for if they have bought it, and if they haven\'t
// If they have:
if($user_has_purchased == true) {
// Now add your code to show the content, which may just be the_content
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_content();
endwhile;
endif;
} else {
// Else here means they are logged in but haven\'t purchased
// You could either show them a message with a link, or auto-redirect
// to the product page to encourage them to buy it
echo "Sorry, this content is only available by purchase.";
}
// Show the sitewide footer
get_footer();
} else {
// Else here means they are not logged in
// So you could either link to the login form, or redirect them there
wp_redirect( wp_login_url() ); exit;
}
?>
(请注意,页眉和页脚仅在用户登录时显示,因为“else”表示要重定向它们。如果已输出页眉,则无法重定向它们。)
如果您的视频显示页面都是自定义的帖子类型,那么这可能是最简单的。只要你有single-posttype.php
设置这些条件后,每次创建其中一个CPT时,它都会检查登录和购买情况。相反,如果您创建一个页面模板,并且必须手动为每个页面应用该模板,则很容易意外忘记设置模板,从而使您的内容意外公开。