SmartFAQ is developed by The SmartFactory (, a division of InBox Solutions (

How to display banner adds in other blocks as well as in header.?
  Requested and Answered by Carnuke on 2004/12/12 11:34:51     10969  reads 
Create a cutom block with the following code:
include_once XOOPS_ROOT_PATH.'/include/functions.php';
$db =& Database::getInstance();
$bannerobject '';
$bresult $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
list (
$numrows) = $db->fetchRow($bresult);
if ( 
$numrows ) {
$numrows $numrows-1;
$bannum mt_rand(0$numrows);
} else {
$bannum 0;
if ( 
$numrows ) {
$bresult $db->query("SELECT * FROM ".$db->prefix("banner"), 1$bannum);
list (
$bid$cid$imptotal$impmade$clicks$imageurl$clickurl$date$htmlbanner$htmlcode) = $db->fetchRow($bresult);
if (
$xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
} 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$datetime());
$db->queryF(sprintf("DELETE FROM %s WHERE bid = %u"$db->prefix("banner"), $bid));
    if (
$bannerobject $htmlcode;
$bannerobject '<center><a href="'.XOOPS_URL.'/banners.php?op=click&bid='.$bid.'" target="_blank">';
        if (
stristr($imageurl'.swf')) {
$bannerobject $bannerobject
.'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=",0,40,0" width="468" height="60">'
.'<param name=movie value="'.$imageurl.'">'
.'<param name=quality value=high>'
.'<embed src="'.$imageurl.'" quality=high pluginspage=""; type="application/x-shockwave-flash" width="468" height="60">'
        } else {
$bannerobject $bannerobject.'<img src="'.$imageurl.'" alt="" />';

$bannerobject $bannerobject.'</a></center>';
Save this with a title and as php script. Position in your Page as required. NOTE: Make sure your adds are suitably sized for the blocks you are using, or else your adds will distort and break out.

The comments are owned by the author. We aren't responsible for their content.

 Does this mean that I can create different size banners?

Does the above described block mean that I can have different size banners?

If yes, how can I assign banners to the different boxes?

Or is it only possible to have one size of banner box shared with all the banner ads?


 Re: Does this mean that I can create different size banners?

I tried this hack as well as two other similar but none of them works. It displays an empty block with just a block title. Is there anything else needed to be done beside just create new block, copy/paste the code and tell it it is php...?


 Re: Does this mean that I can create different size banners?

I used this in a custom block on 2.2.3 Xoops. Displays correctly for me. I have not rotated banners yet but will test later.

Did you set to PHP and not auto? Auto did give me errors.

don (el paso)


 Re: Does this mean that I can create different size banners?

hi there,

I've tried this and it works fine - but can i ask is there any way of specifying to use a vertical banner? (or whatever!).

As the only reason you'd use this is to have different types of banners around your page, it's pretty essential that you can state whether to use the vertical advert or a horizontal one etc etc...

Any ideas?


 Banners in Blocks

Isn't it also possible to create a custom PHP block with only the following inside:



 Re: Banners in Blocks

I use this:
put the following code in a custom block as a php script.

echo xoops_getbanner();


 Re: Banners in Blocks

any ideas how to select a specific banner in a block?

i tried

echo xoops_getbanner(bid);

but it doesnt seems to work


 Re: Banners in Blocks

it's just supposed to be

echo xoops_getbanner();

don't put anything in between the parentheses. It works on my site.


 Re: Banners in Blocks

Has anyone figured out how to get specific banners to show up in a certain place. or to get only vertical banners to show up in one spot and horizontal banners to show up in another spot?


echo xoops_getbanner();

is there a way to tell it which banner to display?


 Revolution of Xoops Banners System

Important news about XOOPS Banners:



 Save as a PHP Script

Remember to save it as a PHP Script not an HTML.
It worked for me perfectly.




Lost Password? Register now!

Who's Online

57 user(s) are online (1 user(s) are browsing XOOPS FAQ)

Members: 0

Guests: 57



Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Did you know ?

Which Module Folders to upload to the server?

Random question

What is the Notifications menu item?