Hello themers! Do you want a simple way to have certain blocks appear only on certain pages or modules on your
PostNuke website? If you are using the "classic" style of
PostNuke theming (with a theme.php), below is some cut-n-paste code that you can add to the block display section to let you customize your block layout! For example, if you only wanted the "category" block to appear on "News" pages, or different Polls to appear with different stories or modules, you can do it easily with the add-in below. It will work with any
PN 7.x "classic" theme.php -- think of it as a "lazy man's
AutoTheme" ;).
How does it work?
To specify custom blocks on your website, you simply edit a single array variable at the top of your theme's themesidebox() function. The array's "keys", on the left, dictate which specific blocks or block type you want to show only on certain pages or modules. The array that follows the "key" value is a comma-separated list of the modules and/or the story/topic/category/section/article id(s) where you want to display that block... The code is well commented at the top (in fact, is mostly comments as it's simple code!) but some notes and things to consider are also at the end of this post.
Here's the Code:
Just inside:
function themesidebox($block) {
of your theme.php, add:
// THEME BLOCK MOD :: For PostNuke theme.php (v 7.x) by Nate Welch // The following mod can be added into any theme.php and lets you specify // blocks to appear on specific pages or modules of your Postnuke Website. // The $show_block array below specifies which specific blocks or block types // are shown on specific modules, topic or section TOC's or articles and stories. // If an existing block type or title is not specified, it will show on all pages. // Blocks are shown in the order specified in the Blocks section of the Admin. // NOTE: If your theme has logic to not show certain block groups, that logic will // override any blocks you may have set below that belong to that group . For example, // many themes use a "if ($GLOBALS['index'] == 1)" to specify only showing certain // blocks groups (right & center) only on the home page. // The keys (left value) of the associative array below is either the title of an // existing block or the name of the block type (see the Blocks Admin). Blocks are // processed in the order they are in the array, so specify specific blocks before // general block types. The values in the array can be the name of the module(s) // that you want the block to appear on, surrounded by single quotes and separated // by commas. You can specify as many modules as you like for each block. You can // also specify specific topics, articles, sections, stories and categories that // you would like a block to appear on. The variables are the same as seen in the // (long) URLs when surfing a PN site and include: sid - a news article id; topic - // a news topic id; secid - a section id; artid - a section article id; catid - a // category of articles; cid - A Web Links Category; lid - a Web Links detail page// id - a Reviews page, PollID - a poll results page.// After the identifying variable, include one or two numbers // indicating either a specific id # or a range of id #'s starting at the first // number specified and ending with the last (inclusive). You can specify multiple // ranges for the same type of id, for example: "'sid',1,4,'sid',7,'sid',15,18" // which would include the block with news stories whose sid is 1 through 4, 7 or // 15 through 18. If you wanted to include a block with *every* news story, you could // simply specify the 'News' module in the array value. To specify a block for the // home page, use the name of the module that you have the home page set to. $show_block =
array('The First Poll' =>
array('catid',
1,
'NS-Admin',
'Recommend_Us',
'Reviews',
'Members_List'),
'The Second Poll' =>
array('sid',
1,
'FAQ',
'Top_List',
'News',
'NS-Admin',
'Search'),
'poll' =>
array('FAQ',
'Sections',
'Reviews',
'Members_List'),
'stories' =>
array('sid',
1,
4,
'FAQ',
'Members_List'),
'thelang' =>
array('Sections',
'Web_Links'),
'category' =>
array('News',
'Sections'),
'Another Block' =>
array('secid',
1,
'sid',
1,
4,
'sid',
9,
11,
'Downloads',
'Members_List'),
'online' =>
array('Reviews',
'FAQ',
'Members_List') );
// Loop through the $show_block array to check for matcheswhile (list($key,
$val) =
each($show_block)) { // Check if a match for either the specific block or the block type if ($block['bkey'] ==
$key ||
$block['title'] ==
$key) { while (list($key2,
$val2) =
each($show_block[$key])) { if ($show_block[$key][$key2] ==
'sid' ||
$show_block[$key][$key2] ==
'topic' ||
$show_block[$key][$key2] ==
'catid' ||
$show_block[$key][$key2] ==
'secid' ||
$show_block[$key][$key2] ==
'artid' ||
$show_block[$key][$key2] ==
'lid' ||
$show_block[$key][$key2] ==
'cid' ||
$show_block[$key][$key2] ==
'id' ||
$show_block[$key][$key2] ==
'pollID') { if (pnVarCleanFromInput
($show_block[$key][$key2]) ==
$show_block[$key][$key2+1] ||
(pnVarCleanFromInput
($show_block[$key][$key2]) >=
$show_block[$key][$key2+1] && pnVarCleanFromInput
($show_block[$key][$key2]) <=
$show_block[$key][$key2+2] &&
intval($show_block[$key][$key2+2]) !=
0)) break 2;
} elseif ($show_block[$key][$key2] ==
$GLOBALS['ModName']) break 2;
} // End of second while loop return;
} // End of matched block } // End of first while loop // END THEME BLOCK MOD
... then the rest of your themesidebox() function. The only part you have to change to customize your website's blocks is the $show_block array variable at the top.
Notes on Usage
The left values in the array represent the different blocks (either individual or block types) whose display you want to restrict to certain pages or modules. The value of these "keys" will be either the "Title" of the block you want to customize (as seen in the header of the block itself or under the "Title" column of the "view blocks" in blocks admin) or the "Name" of the block (seen under the "Name" column of the "view blocks"). Specifying an existing "Title" for the block will customize that specific block only, and if you change the Title of the block you must also change it in this array. Specifying the "name" of the block will customize an entire block type, such as Polls. If you are specifying both an individual Poll block (
i.e., "Poll of the Day") and the general Poll block type ("poll"), you should specify the individual block first in the array, otherwise it will be overridden by the general block type. You may only specify an individual block or block type once in the array.
If an active block is not specified in the array, it will show up on every page it would normally show up.
The sub-array for each of the "key" values (right of the "=>") determines which modules or pages the block or block type specified before the "=>" will show up on. The values in this sub-array are separated by commas and you can have as many as you want for each block or block type specified. To have a certain block appear on all the pages of a specific module, put the Module name(s) in this array,
i.e. "News","Downloads","NS-Admin". The module names can be seen by listing them in the Admin->Modules part of
PostNuke or by browsing the /modules directory. Note: not all modules have "content pages" on your
PostNuke Website. If you want to see what pages use a particular module, check out the "long"
URL or echo $GLOBALS['ModName'] somewhere in your theme and surf your website!
You can also specify specific pages on your website to display certain blocks. First, specify the identifier of the page item - for News articles it's "sid", for example. Then, specify either one or two numbers representing the ID numbers of the articles/topics/etc... that you want to include the block on. If you specify one number after the identifier it will include the block on just the page with an identifier matching that number. If you include two numbers after the identifier, you will specify a range of pages matching the first through second values you specified. A list of supported identifiers is in the comments of the script above.
For example, to include a block on a news item whose identifier, sid, is "5", you would add this to the array:
'My Block' =>
array('sid',
5),
To include the block on news stories with an id of 10 through 20:
'My Block' =>
array('sid',
10,
20),
You can include non-sequential and multiple identifiers, too:
'My Block' =>
array('sid',
5,
10,
'sid',
14,
'sid',
20,
30,
'topic',
2),
Which would add the block whose title is "My Block" to news article pages whose sid is 5 through 10, 14 or 20 through 30 *and* topic pages whose topic id is 2.
Things to Consider:
Many themes have logic in them to not show certain block groups often when you're not on the home page, such as the right blocks, etc... If this is the case, modify your theme as necessary or any blocks in those areas will not show regardless of what you put in the array.
CASE-SENSITIVITY is in effect. Take special note of the case of letters when entering Module names, identifiers (sid, catid, etc...) block types and specific block titles. They are all case-sensitive!
If you are not familiar with
PHP arrays, take special note of the format of the $show_block array when editing. This is a "two-dimensional" array where each of the blocks you specify has an array of its own. The values within both the "outer" array (the blocks you are customizing) and the "inner" array (the parameters for each block) are separated by commas. Text values are surrounded by single quotes and with numerals the quotes are optional. Take note also of the closing parenthesis of the "outer" array and the semicolon that ends the
PHP line.
The above code does not add any new "areas" or "zones" to your theme. However, the above mod is irrespective of zones so should work with any other "hacks" you may have made to the themesidebox() function in your theme.php.
This mod can be mixed with some of my and other's theme block mods, but keep in mind if you use any mods that include parsing out extra data in the block title (via a delimeter, etc...) take that into consideration as the code above checks for $block[title] (you may want to change that to your parsed title, etc...)
That's It! I hope you enjoy - if you use your creativity, I think you can get a lot of mileage out of this simple code... Any feedbacks or comments are welcome!
--
Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods
Cape Cod Travel Info...