Javascript 使用WordPress header.php-如何生成<;链接>;动态交替?
我有两个网站,一个是WordPress,另一个是SPA HTML+jQueryMobile 我从谷歌上读到这篇文章: 它谈到保持两个网站的连接,因为它们是相同的。它改变了,只是移动和桌面的类型 对于移动端,没有问题,因为在每个HTML页面上,我都像谷歌所说的那样在每个Javascript 使用WordPress header.php-如何生成<;链接>;动态交替?,javascript,php,jquery,html,wordpress,Javascript,Php,Jquery,Html,Wordpress,我有两个网站,一个是WordPress,另一个是SPA HTML+jQueryMobile 我从谷歌上读到这篇文章: 它谈到保持两个网站的连接,因为它们是相同的。它改变了,只是移动和桌面的类型 对于移动端,没有问题,因为在每个HTML页面上,我都像谷歌所说的那样在每个标签中添加,但在桌面版上,我有一个WordPress网站,所以我有haeder.php,它出现在每个HTML中,因为它是动态的,那么,我如何在标签中动态写入,检查刚刚加载的页面并放置正确的链接 如果我把这个硬编码放在header.
标签中添加
,但在桌面版上,我有一个WordPress网站,所以我有haeder.php
,它出现在每个HTML中,因为它是动态的,那么,我如何在
标签
中动态写入,检查刚刚加载的页面并放置正确的链接
如果我把这个硬编码放在header.php中
<link rel="alternate" media="only screen and (max-width: 640px)" href="http://www.example.com/Mobile/pageexample.html" >
但是在我的例子中,标记没有ID属性,这很棘手。我怎样才能修好它
下面的工作可以吗?但我需要为每个与移动网站有通信的页面写一个“如果”声明
<head>
<link rel="alternate" media="only screen and (max-width: 640px)" href="<?php CheckAlternate(); ?>" >
</head>
<?php
function CheckAlternate(){
if strstr(curPageURL,"page2")
return "www.example.com/Mobile/MobilePage2.html"
}
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
通过这种方式,客户机发出一个请求,响应中已经包含了正确的标记
,我已经找到了阅读edit2的解决方案,但是仍然有一个小问题,如何打印HTML代码而不是在php代码中进行简单的测试。感谢您解决了这个问题,从下面的代码$sBaseLinkAlternate.'>'中删除“htmlspecialchars”()就足够了;
$('#yourElementId').attr('title', 'your new title');
<head>
<link rel="alternate" media="only screen and (max-width: 640px)" href="<?php CheckAlternate(); ?>" >
</head>
<?php
function CheckAlternate(){
if strstr(curPageURL,"page2")
return "www.example.com/Mobile/MobilePage2.html"
}
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
<head>
-- HTML code--
<?php echo checkAlternate(); ?>
-- HTML Code--
<?php
function checkAlternate(){
$sBaseLinkAlternate = "<link rel='alternate' media='only screen and (max-width: 640px)' href='";
$sPaginaAttuale = curPageURL();
switch ($sPaginaAttuale) {
case "http://www.example.com/home/":
return htmlspecialchars($sBaseLinkAlternate) . "http://www.example.com/Mobile/home.html'>";
break;
}
}//end checkAlternate--
?>
<head>