2016-04-21 90 views
1

我在wordpress中设置了一个基于各种变量生成内容的页面。它会创建一个字符串,它是Google日历的网址。然后,Google日历通过iframe嵌入,但Google日历托管在我们的域名上。我无法弄清楚如何将字符串传输到iframe中。 下面是代码:将PHP变量传递到嵌入在IFRAME中的另一个PHP文件

<?php if (is_page('baseball')) { 
    $current_sport = 'Baseball'; 
    $athletic_calendar = get_field('calendar_baseball', 'option'); 
    $athletic_calendar_boys_varsity = get_field('boys_varsity_calendar_basketball', 'option'); 
    $athletic_calendar_girls_varsity = get_field('girls_varsity_calendar_basketball', 'option'); 
    $athletic_calendar_boys_jv = get_field('boys_jv_calendar_basketball', 'option'); 
    $athletic_calendar_girls_jv = get_field('girls_jv_calendar_basketball', 'option'); 
    $athletic_calendar_boys_freshmen = get_field('boys_freshmen_calendar_basketball', 'option'); 
    $athletic_calendar_girls_freshmen = get_field('girls_freshmen_calendar_basketball', 'option'); 
    } ?> 
    <?php $calendar_string = 'src=' . $athletic_calendar . '&'; 
    if ($athletic_calendar_boys_varsity) : 
    $calendar_string .= 'src=' . $athletic_calendar_boys_varsity . '&'; 
    endif; 
    if ($athletic_calendar_girls_varsity) : 
    $calendar_string .= 'src=' . $athletic_calendar_girls_varsity . '&'; 
    endif; 
    if ($athletic_calendar_boys_jv) : 
    $calendar_string .= 'src=' . $athletic_calendar_boys_jv . '&'; 
    endif; 
    if ($athletic_calendar_girls_jv) : 
    $calendar_string .= 'src=' . $athletic_calendar_girls_jv . '&'; 
    endif; 
    if ($athletic_calendar_boys_freshmen) : 
    $calendar_string .= 'src=' . $athletic_calendar_boys_freshmen . '&'; 
    endif; 
    if ($athletic_calendar_girls_freshmen) : 
    $calendar_string .= 'src=' . $athletic_calendar_girls_freshmen . '&'; 
    endif; 
    global $gcal_string; 
    $gcal_string = 'https://www.google.com/calendar/embed?' . $calendar_string . 'ctz=America/Chicago'; 
    ?> 
    <?php echo '<iframe src="https://www.bmchs.org/gcal-custom.php" style="border-width:0" width="100%" height="685" frameborder="0" scrolling="no"></iframe>' ;?> 

然后在这里是兆千卡,custom.php代码:

<?php 
$content = file_get_contents('https://www.google.com/calendar/embed?src=bmchs.org_2i1q9e2a5o3ud6d9qji33a2reg%40group.calendar.google.com&ctz=America/Chicago'); 
$content = str_replace('</title>','</title><base href="https://www.google.com/calendar/" />', $content); 
$content = str_replace('//calendar.google.com/calendar/static/2feb9b53c01cf3989b70175c72c580c5embedcompiled_fastui.css','https://www.bmchs.org/calendar.css', $content); 
echo $content; ?> 

我需要在兆千卡,custom.php发生是这样的:

$content = file_get_contents($gcal_string); 

这可能吗?我不知道...

+0

你会做你的同事,每个人都会在你的代码上阅读你的代码,最后但并非最不重要的一个大恩,如果你想写“可读”的代码。 –

+0

你为什么要为此使用iframe? – Scopey

+0

正确。以前的iframe是