----------------------------------------------------------------------------------------------------------
以下的方法可以讓你把任何你想要的banner放在你想要的地方,
有三種選擇的方式可以使用:
Step 1.
找到xoops安裝路徑
xoops root_directory/include/
然後打開 functions.php檔案
在檔案的最後結尾?>符號前輸入以下語法:
<code>
function getbanner_from_id_banner($banner_id)
{ ###### Hack by www.stefanosilvestrini.com ###### global $xoopsConfig; $db =& Database::getInstance(); $bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner")." WHERE bid = ". $banner_id);
list ($numrows) = $db->fetchRow($bresult);
if ( $numrows > 1 ) { $numrows = $numrows-1; mt_srand((double)microtime()*1000000); $bannum = mt_rand(0, $numrows);
} else { $bannum = 0;
}
if ( $numrows > 0 ) { $bresult = $db->query("SELECT * FROM ".$db->prefix("banner")." WHERE bid = ". $banner_id, 1, $bannum);
list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) { // EMPTY } else { $db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
} /* Check if this impression is the last one and print the banner */ if ( $imptotal == $impmade ) { $newid = $db->genId($db->prefix("bannerfinish")."_bid_seq"); $sql = sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)", $db->prefix("bannerfinish"), $newid, $cid, $impmade, $clicks, $date, time()); $db->queryF($sql); $db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
}
if ($htmlbanner){ $bannerobject = $htmlcode;
}else{ $bannerobject = '<div align="center"><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" rel="nofollow">';
if (stristr($imageurl, '.swf')) { $bannerobject = $bannerobject .'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'.'<param name="movie" value="'.$imageurl.'"></param>' .'<param name="quality" value="high"></param>' .'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' .'</embed>' .'</object>';
} else { $bannerobject = $bannerobject.'<img src="'.$imageurl.'" alt="" />';
}
$bannerobject = $bannerobject.'</a></div>';
}
return $bannerobject;
}
}
function getbanner_from_id_client($client_id)
{ ###### Hack by www.stefanosilvestrini.com ###### global $xoopsConfig; $db =& Database::getInstance(); $bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner")." WHERE cid = ". $client_id);
list ($numrows) = $db->fetchRow($bresult);
if ( $numrows > 1 ) { $numrows = $numrows-1; mt_srand((double)microtime()*1000000); $bannum = mt_rand(0, $numrows);
} else { $bannum = 0;
}
if ( $numrows > 0 ) { $bresult = $db->query("SELECT * FROM ".$db->prefix("banner")." WHERE cid = ". $client_id ." ORDER BY rand()", 1, $bannum);
list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) { // EMPTY } else { $db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
} /* Check if this impression is the last one and print the banner */ if ( $imptotal == $impmade ) { $newid = $db->genId($db->prefix("bannerfinish")."_bid_seq"); $sql = sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)", $db->prefix("bannerfinish"), $newid, $cid, $impmade, $clicks, $date, time()); $db->queryF($sql); $db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
}
if ($htmlbanner){ $bannerobject = $htmlcode;
}else{ $bannerobject = '<div align="center"><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" rel="nofollow">';
if (stristr($imageurl, '.swf')) { $bannerobject = $bannerobject .'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'.'<param name="movie" value="'.$imageurl.'"></param>' .'<param name="quality" value="high"></param>' .'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">' .'</embed>' .'</object>';
} else { $bannerobject = $bannerobject.'<img src="'.$imageurl.'" alt="" />';
}
$bannerobject = $bannerobject.'</a></div>';
}
return $bannerobject;
}
}
</code>
然後把檔案儲存關閉。
以下有三種簡單的方法可以選擇:
方法一:
在xoops的區塊管理內自訂一個區塊,然後選擇內容類型為php腳本。
把echo xoops_getbanner();貼在內容欄位裡面
然後在廣告管理的地方,把廣告啓動即可(不論廣告有的數量)
方法二:
在xoops的區塊管理內自訂一個區塊,然後選擇內容類型為php腳本。
把echo getbanner_from_id_banner(ID_BANNER);貼在內容欄位裡面
然後在廣告管理的地方,把廣告啓動即可(不論廣告有的數量),ID_BANNER就是廣告的ID號碼,
用,用這個語法,可以新增不同的區塊,然後再不同的區塊,顯示不同的廣告
方法三:
在xoops的區塊管理內自訂一個區塊,然後選擇內容類型為php腳本。
把echo getbanner_from_id_client(ID_CLIENT);貼在內容欄位裡面
然後在廣告管理的地方,把廣告啓動即可(不論廣告有的數量),ID_CLIENT就是廣告的客戶名稱,如果該客戶有10個廣告,那麼區塊就只會針對這個客戶的10個廣告隨機輪播。