我在wordpress中设置了一个页面,该页面根据各种变量生成内容。它会创建一个字符串,该字符串是指向 Google 日历的 URL。然后,谷歌日历通过iframe嵌入,尽管谷歌日历托管在我们的域上。我不知道如何将字符串传输到 iframe 中。这是代码:
<?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>' ;?>
然后这是gcal-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; ?>
我需要在gcal自定义中发生的是.php是这样的:
$content = file_get_contents( $gcal_string);
这可能吗?我想不通...
你似乎用$calendar_string
和$gcal_string
构建了一个GET-字符串,但你从来没有在iframe
中使用它。
您的iframe
的源代码只是一个没有任何变量的静态字符串:
<iframe src="https://www.bmchs.org/gcal-custom.php" style="border-width:0" width="100%" height="685" frameborder="0" scrolling="no"></iframe>
变量值不会神奇地进入那里。
为什么不使用可能为此目的构建的字符串?
<?php echo '<iframe src="https://www.bmchs.org/gcal-custom.php?' . $calendar_string . '"></iframe>'; ?>
然后读取 gcal-custom.php
中的 GET 变量;例如:
<?php
$my_src = $_GET["src"];
?>
另一种可能性是将您的值保存到会话变量中,然后读取在iframe
中打开的 PHP 文件中的值。