【问题标题】:Wordpress site with php script does not work after publishing带有 php 脚本的 Wordpress 站点在发布后无法正常工作
【发布时间】:2021-05-27 03:19:37
【问题描述】:

我在 Wordpress 上有一个网站,我想拥有完全可修改(样式等)的谷歌日历。

我用的是pp脚本(下)

<?php
$your_google_calendar="https://calendar.google.com/calendar/embed?src=c2hkshh3lilu6ig3p1899gonqc%40group.calendar.google.com&ctz=Europe%2FWarsaw";

$url= parse_url($your_google_calendar);
$google_domain = $url['scheme'].'://'.$url['host'];

// Load and parse Google's raw calendar
$dom = new DOMDocument;
$dom->loadHTMLfile($your_google_calendar);

// Create a link to a new CSS file called schedule.min.css
$element = $dom->createElement('link');
$element->setAttribute('type', 'text/css');
$element->setAttribute('rel', 'stylesheet');
$element->setAttribute('href', 'schedule.min.css');

// Change Google's JS file to use absolute URLs
$scripts = $dom->getElementsByTagName('script');

foreach ($scripts as $script) {
  $js_src = $script->getAttribute('src');
  
  if ($js_src) {
    $parsed_js = parse_url($js_src, PHP_URL_HOST);
    if (!$parsed_js) {
      $script->setAttribute('src', $google_domain . $js_src);      
    }
  }
}

 // Append this link at the end of the element
$head = $dom->getElementsByTagName('head')->item(0);
$head->appendChild($element);

// Remove old stylesheet
$oldcss = $dom->documentElement;
$link = $oldcss->getElementsByTagName('link')->item(0);
$head->removeChild($link);

// Export the HTML
echo $dom->saveHTML();
?>

我已经(使用 Elementor)在我的网站上放置了一个 html 代码:

<iframe style="border-width: 0;" src="./wp-content/themes/neve/calendar.php" width="560" height="400" frameborder="0" scrolling="no"></iframe>

在此站点被设置为草稿之前,一切正常。当我点击发布按钮时,我遇到了错误,好吧,也许不是错误,但我没有将谷歌日历加载为我网站的一部分,而是从我的 wordpress 网站获得了默认的“找不到页面”屏幕。

有没有人知道发布后发生了什么,该网站无法正常工作? 如果我返回草稿,网站将再次正常工作。

我的 php 脚本和 css 文件位于:./wp-content/themes/neve/ 文件夹中。

编辑编辑编辑

我项目中的 .css 示例,向您展示“完全可修改”的含义。

.view-container-border {
    background: transparent;
}

.view-cap {
    background: transparent;
}

.mv-event-container { 
    border-top: 1px solid black; 
}

.mv-daynames-table { 
    color: black; 
    background: transparent; 
    text-transform: uppercase;
}

.st-dtitle {
    background: #EAEAEA;
    text-align: center;
}

.st-bg-today, .st-dtitle-today {
    background: #EAEAEA;
    border: none;
    text-align: center;
}

多亏了这一点,我的日历看起来像: 附言。 “zajęty (a)”表示这是一个公共日历,其中设置了“仅显示忙碌”选项。

【问题讨论】:

  • 什么是完全可修改的?您希望将您的谷歌日历嵌入到您的页面中,并使用您分配的任何参数(CSS、Google 等)?
  • 是的,当我在设置为草稿的页面上实现上述解决方案时,我可以借助 css 文件更改所有元素。我在主帖中添加了我的示例的 .css 代码。
  • 您是否会在functions.php 中包含您将CSS 排队的顺序?也许这种排序或缓存会导致您的问题......
  • 我根本没有更改functions.php。我刚刚添加了新文件 calendar.php 并将其放入我的页面代码中。

标签: php html wordpress calendar


【解决方案1】:

可以在您的主题中嵌入您的 Google 日历,方法是包含 Google 提供的用于嵌入日历的 &lt;iframe&gt;。他们在日历设置页面上提供的此代码应粘贴到您的模板之一中。与其尝试使用 PHP 构建 &lt;iframe&gt; 标记,不如将其放在主题中的一个 PHP 模板中。根据您的主题,这可能是任意数量的模板,但无论是哪一个,只需包含应类似于此的 &lt;iframe&gt; 标记:

&lt;iframe src="https://calendar.google.com/calendar/embed?src=c2hkshh3lilu6ig3p1899gonqc%40group.calendar.google.com&amp;ctz=Europe%2FWarsaw" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;

例如,如果您想将日历放置在假设的“联系人”页面上,则在模板 content.php 中放置由 Google 提供的 &lt;iframe&gt; 标签,您已经在 the Google calendar settings 中找到该标签。

<?php 
.......
?>
<h1>My Google Calendar</h1>
<iframe src="https://calendar.google.com/calendar/embed?src=c2hkshh3lilu6ig3p1899gonqc%40group.calendar.google.com&ctz=Europe%2FWarsaw" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
  

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-12-07
  • 1970-01-01
  • 2013-12-26
  • 1970-01-01
  • 1970-01-01
  • 2018-02-17
  • 2014-06-27
  • 2019-10-03
相关资源
最近更新 更多