2014-02-14 32 views
0

基本上,我正在尋找可能的最簡單代碼來解決此問題。當爲iframe src填充自定義字段時,我有一個填充的iframe。如果存在自定義字段,則顯示代碼/元素

基本上,我想如果自定義字段沒有填寫,iframe代碼完全消失。

這是這樣我就可以在彈出page.php文件的代碼和iframe,只顯示,如果自定義字段被填充。

<?php 
    $iframe_src = get_post_meta(get_the_ID(), 'iframe_src', true); 
    $iframe_height = get_post_meta(get_the_ID(), 'iframe_height', true); 

    $height = ($iframe_height == "" || !$iframe_height) ? 2650 : $iframe_height; 
?> 
<iframe SRC="<?php echo $iframe_src; ?>" WIDTH="100%" HEIGHT="<?php echo $height; ?>" frameborder="0" scrolling="no" name="content"></iframe> 
+1

'如果($ iframe_src = ''!){...}'? – putvande

+0

對不起,我很新,我在哪裏放? – user3181828

回答

0

你可以只檢查是否$iframe_src設置,如:

<?php 
    if(!empty($iframe_src)) { 
     ?><iframe SRC="<?php echo $iframe_src; ?>" WIDTH="100%" HEIGHT="<?php echo $height; ?>" frameborder="0" scrolling="no" name="content"></iframe><?php 
    } 
?> 
+0

不幸的是,沒有顯示出來。此頁面已填充iframe SRC,但它不能在頁面上工作:http://projectprintsolutions.pps.staging.wpengine.com/print-products/3d-merchandisers/ – user3181828

+0

我想它沒有,否則你的iframe wouldn'沒有來源。 – putvande

+0

你有什麼建議嗎? – user3181828

相關問題