亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 101 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號