为了账号安全,请及时绑定邮箱和手机立即绑定

Wordpress 高级自定义字段变量未呈现

Wordpress 高级自定义字段变量未呈现

PHP
慕雪6442864 2023-03-11 17:22:31
我正在使用一个名为 Pay for Post with Woocommerce 的插件,它隐藏了帖子或部分帖子,并允许您使用 woocommerce 产品出售对该帖子的访问权。插件作者向我发送了这个脚本,我可以用它来创建页面模板:<?phpif(Woocommerce_Pay_Per_Post_Helper::is_protected()){   //Page is protected   if(Woocommerce_Pay_Per_Post_Helper::has_access()){      // Do what you want to do if they have access to the page   } else {      // the page is protected and the user does NOT have access      echo Woocommerce_Pay_Per_Post_Helper::get_no_access_content();   }} else {   //Page is not protected do what you need to do.}我正在尝试根据产品是否已购买来创建页面的自定义版本,但我无法让我的高级自定义字段变量在我的页面模板中正确呈现。这是我为测试目的创建的。<?php while ( have_posts() ) : the_post(); ?><?php$video_screenshot = the_field("video_screenshot");$video_link = the_field("video_link");    if(Woocommerce_Pay_Per_Post_Helper::is_protected()){    //Page is protected        if(Woocommerce_Pay_Per_Post_Helper::has_access()){            // Do what you want to do if they have access to the page            echo '<div class="container"><div class="row"><div class="col-12"><iframe width="560" height="315" src="{$video_link}" frameborder="0" allowfullscreen></iframe></div></div></div>';        } else {            // the page is protected and the user does NOT have access            echo Woocommerce_Pay_Per_Post_Helper::get_no_access_content();            echo '<div class="container"><div class="row"><div class="col-12"><img src="{$video_screenshot}" /></div></div></div>';        }    } else {    //Page is not protected do what you need to do.    } ?><?php endwhile; // end of the loop. ?>在上面的示例中,当我查看尚未购买的页面时,它应该呈现一个链接,其中包含从帖子自定义字段生成的源,但它只是打印字符串内的值:<img src="{$video_screenshot}">我已经尝试了很多方法,但我无法确定如何将这些变量包含在字符串中并让它们按应有的方式打印。任何帮助将非常感激!
查看完整描述

1 回答

?
30秒到达战场

TA贡献1828条经验 获得超6个赞

以下是如何稍微重构代码,以更易读的方式回显变量:


<?php while ( have_posts() ) : the_post();


    if(Woocommerce_Pay_Per_Post_Helper::is_protected()){


    //Page is protected


        if(Woocommerce_Pay_Per_Post_Helper::has_access()){


            // Do what you want to do if they have access to the page ?>


            <div class="container">

                <div class="row">

                    <div class="col-12">

                        <iframe width="560" height="315" src="<?php echo the_field("video_link"); ?>" frameborder="0" allowfullscreen></iframe>

                    </div>

                </div>

            </div> 


        <?php } else {


            // the page is protected and the user does NOT have access


            echo Woocommerce_Pay_Per_Post_Helper::get_no_access_content(); ?>


            <div class="container">

                <div class="row">

                    <div class="col-12">

                        <img src="<?php echo the_field("video_screenshot") ?>" />

                    </div>

                </div>

            </div>


        <?php }


    } else {


    //Page is not protected do what you need to do.


    } 


endwhile; // end of the loop. ?>


查看完整回答
反对 回复 2023-03-11
  • 1 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信