我想执行多个不同的PHP代码段,这些代码段都会检索1个页面ID(是的,我想扩展代码并显示页面ID以外的其他内容)。
但如果我同时执行2个或更多代码段,我会得到一个空白页。。。
我的问题是,我如何修复这个错误,为什么以及如何导致这个错误?
这是我从错误日志中得到的信息:
【2017年10月11日星期三08:14:06.322845】【proxy\\u fcgi:error】【pid 5616:tid 140278597940992】【客户端xx.xxx.xxx.xxx:xxxxx】AH01071:获取错误“PHP消息:PHP致命错误:无法重新声明getPages()(之前在/var/www/vhosts/classymagazin.de/httpdocs/wp-content/plugins/insert-PHP代码段/短代码处理程序中声明)。PHP(29):eval()\'d代码:5)在/var/www/vhosts/classymagazin中声明。de/httpdocs/wp-content/plugins/insert-php代码段/shortcode处理程序。php(29):eval()\'d第12行的代码\\n\'
这是最新页面的PHP代码:
<?php
function getPages(){
$args = array(
\'sort_order\' => \'desc\',
\'sort_column\' => \'post_date\',
\'post_type\' => \'page\',
\'number\' => \'26\',
\'post_status\' => \'publish\');
return get_pages($args);
}
function filterPages($allNews, $pages){
foreach($pages as $page) {
$pid = $page->ID;
$object = get_the_category($pid);
$termsForPost = array();
foreach($object as $terms) {
if($terms->term_id == 15 || $terms->term_id == 16){
$termsForPost[] = $terms->term_id;
}
}
if(in_array(15, $termsForPost) && in_array(16, $termsForPost)){
$allNews[$pid] = array("ID" => $pid, "Sticky" => true, "Timestamp" => get_the_time(\'U\', $pid), "Title" => get_the_title($pid));
}else if(in_array(15, $termsForPost)){
$allNews[$pid] = array("ID" => $pid, "Sticky" => false, "Timestamp" => get_the_time(\'U\', $pid), "Title" => get_the_title($pid));
}
}
return $allNews;
}
function sortPages($allNews){
$stickyPosts = array();
$nonStickyPosts = array();
foreach($allNews as $article){
if($article["Sticky"] == true){
$stickyPosts[] = $article["ID"];
}else{
$nonStickyPosts[] = $article["ID"];
}
}
$allNews = null;
foreach($stickyPosts as $tmp){
$allNews[] = $tmp;
}
foreach($nonStickyPosts as $tmp){
$allNews[] = $tmp;
}
return $allNews;
}
function getAllArticle($index = 0){
if($index == 0){
$allNews = array();
$pages = getPages();
$allNews = filterPages($allNews, $pages);
$allNews = sortPages($allNews);
foreach($allNews as $article){
var_dump($article);
echo "<br>";
}
}else{
$allNews = array();
$pages = getPages();
$allNews = filterPages($allNews, $pages);
$allNews = sortPages($allNews);
var_dump($allNews[$index - 1]);
}
}
getAllArticle(1);
?>
亲切的问候