1
jboybags
visibility of blocks inquiry
  • 2005/8/25 5:50

  • jboybags

  • Just popping in

  • Posts: 12

  • Since: 2005/7/28


in the blocks administration page, i want to customize the "Visible in" section. In the default, the "Visible in" displays all module pages, top pages and stuff like that.. what if I wanted to display a block only in a certain page. nad not the whole pages of the module... is this possible?

eg:

Vible in:
All Pages
Contact Us
Wallpaper


Where can I modify this section such that in can also have an option for specific pages only?

Thank you very much!

2
Antoine
Re: visibility of blocks inquiry
  • 2005/8/25 9:04

  • Antoine

  • Friend of XOOPS

  • Posts: 112

  • Since: 2004/11/14


I think that a workaround would be to disable certain blocks from your module code if you do not want them displayed even when they belong to your module. After the page has been rendered you could enable the block again so that it is displayed normally again within modules.
This would involve looking up the block's bid in the xoops_newblocks table.
I whipped up this bit of code. Haven't tested it at all so I hope that it works:
<?php
/**
 * Functions to temporarily hide or show certain blocks so they can be 
 * made to be visible in some pages of a module instead of all
 *
 * Invoke disableBlock before including header.php in a module
 * Invoke enableBlock after including footerphp in a module
 * @author  Dirk Louwers <dirk,louwers@symtech.nl>
 * @copyright (c) 2005 Dirk Louwers
 * @example 
 * (...)
 * disableBlock(12, true);
 * include('../../header.php');
 * (...)
 * include('../../footer.php');
 * enableBlock(12, true);
 * (...)
 */

/**
 * Disables a block by making it invisible
 * @param int $blockid
 * @param bool $force set to true if you have any GET variables
 * in the page request
 * @return false on error, else true
 */
// public
function disableBlock($blockid$force=false)
{
    global 
$xoopsDB;
    
    if(
intval($blockid 0))
    {
        
$sql 'Update '.$xoopsDB->prefix('newblocks').' Set visible=0'
            
.' Where bid='.intval($blockid);
        if(
$force) {
            
$result $xoopsDB->queryF($sql);
        }
        else {
            
$result $xoopsDB->query($sql);
        }
        if(!
$result) return false;
        return 
true;
    }
    return 
false;
}

/**
 * Enables a block by making it visible
 * @param int $blockid
 * @param bool $force set to true if you have any GET variables
 * in the page request
 * @return false on error, else true
 */
// public
function enableBlock($blockid$force=false)
{
    global 
$xoopsDB;
    
    if(
intval($blockid 0))
    {
        
$sql 'Update '.$xoopsDB->prefix('newblocks').' Set visible=1'
            
.' Where bid='.intval($blockid);
        if(
$force) {
            
$result $xoopsDB->queryF($sql);
        }
        else {
            
$result $xoopsDB->query($sql);
        }
        if(!
$result) return false;
        return 
true;
    }
    return 
false;
}
?>
.

Login

Who's Online

161 user(s) are online (106 user(s) are browsing Support Forums)


Members: 0


Guests: 161


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits