我抓住了以下代码来抓取当前页面网址...
<?php
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;
}
?>
通过这种方式,我可以将当前页面网址放入类似我的模板的Facebook按钮...
<div class="fb-like" data-href="<?php echo curPageURL(); ?>" data-layout="button" data-action="like" data-show-faces="true" data-share="true"></div>
这在我的Wordpress网站的所有页面上都能正常工作,但我在最新的帖子页面上收到错误。我不能在不收到此错误的情况下发布多个帖子...
致命错误:无法重新声明/ home4 / whimint / public_html / whetink中的curpageurl()(之前在/home4/whimint/public_html/whetink.co/wp-content/themes/kingdom/content.php:81中声明)。第90行的co / wp-content / themes / kingdom / content.php
有什么想法?如果您需要更多详细信息,请告诉我,我是Stack Overflow的新手。提前谢谢!
答案 0 :(得分:0)
致命错误:无法重新声明/ home4 / whimint / public_html / whetink中的curpageurl()(之前在/home4/whimint/public_html/whetink.co/wp-content/themes/kingdom/content.php:81中声明)。第90行的co / wp-content / themes / kingdom / content.php
此错误表示您的文件中的函数是两次(content.php)。一次在第81行,一次在第90行。
您的代码以驼峰形式显示函数,错误为小写。 php函数不区分大小写。 您是否尝试使用相同(不区分大小写)名称的多个函数?
答案 1 :(得分:0)
将函数移动到functions.php文件中,使其仅声明一次。您也可以将其包装在其中,以防止它被声明两次。
if(!function_exists("curPageURL")){
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;
}
}