i need a finer grain of control than the current visibility options of "Show on every page except the listed pages" and "Show on only the listed pages". i would love to see the "Show if the following PHP code returns TRUE" option added to this great module.

i tried to compare the block.module "Page specific visibility settings" code to the nodeteaser section, but i'm not a coder. :-(

i have the nodeteaser.module last updated Nov 12, 2006.

can anyone help?

Comments

jillelaine’s picture

Assigned: Unassigned » jillelaine
Status: Active » Needs review
StatusFileSize
new4.95 KB

Here is a patch that adds the option to control the nodeteaser visibility with PHP code in administer > settings > nodeteaser.

To apply the patch, copy the nodeteaser-phpcode_for_visibility.patch into the same folder as your nodeteaser.module. Then, at the command line in the same folder:

patch <nodeteaser-phpcode_for_visibility.patch

This command will create a backup of your nodeteaser.module named nodeteaser.module.orig and patch the nodeteaser.module.

To use the "PHP code for visibility" option, you must have permission to:

  • "administer nodeteaser" in administer > access control > nodeteaser module.
  • "use PHP for block visibility" in administer > access control > block.
  • use "PHP code" in administer > input formats > PHP code > configure.

If your permissions are correctly set, you can:

  • select the option to "Show if the following PHP code returns TRUE (PHP-mode, experts only)." in administer > settings > nodeteaser
  • and then type in PHP code into the "Pages:" textfield and "save configuration".
  • NOTE -> you must disable any WYSIWYG editors on the "Pages:" textfield: WYSIWYG editors will create hash of your PHP code.

Please see this section of the Drupal handbook to learn about using PHP code for visibility: http://drupal.org/node/60317

Here is some sample PHP code that will show the nodeteaser on only certain "content types" -> blogs, book pages, and pages:

<?php
$match = FALSE;

/* this section controls visibility on EXISTING content */

$types = array('blog' => 1, 'book' => 1, 'page' => 1);
if (arg(0) == 'node' && is_numeric(arg(1))) {
$nid = arg(1);
$node = node_load(array('nid' => $nid));
$type = $node->type;
if (isset($types[$type])) {
  $match = TRUE;
}
}

/* this section controls visibility on NEW content */

if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/blog")
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/book")
{ $match = TRUE;}
if (substr($_SERVER["REQUEST_URI"], 0) == "/node/add/page")
{ $match = TRUE;}

return $match;
?>

To use the above code, copy and paste all of the text within the grey block into the "Pages:" textfield. Modify the code to your desired "content type(s)", but be sure to replace the "content type" in both the EXISTING and NEW sections. More information about visibility by "content type" can be found here: http://drupal.org/node/76675

To show the nodeteaser to only certain user roles (in Drupal 4.7), see this page: http://drupal.org/node/86241

This patch has been tested in both my testbed and live Drupal 4.7 sites. Please review and offer feedback. Thank you.

jillelaine’s picture

please see this comment for improved code to control Node Teaser visibility and access with PHP code:

http://drupal.org/node/76675#comment-186602

ideaoforder’s picture

Status: Needs review » Fixed

This has been added officially to the 5.0 release, thanks to Jill.

Anonymous’s picture

Status: Fixed » Closed (fixed)