getting block to show up for specific pages and specific node type

View: New views
4 Messages — Rating Filter:   Alert me  

getting block to show up for specific pages and specific node type

by brendan, fresh-off.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello,

I found a code snippet on drupal.org that allows a block to be shown only on specific node types when 'Show if the following PHP code returns TRUE' is checked on the Configure Blocks page:

 

-----

<?php
if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
  $thenode = node_load(arg(1));’
  if ($thenode->type == 'blog') {
    return TRUE;
  }
}
?>

-----


this works great, except for that I’d like the block to show for nodes of type “blog” AND also on specific pages – in my case www.mysite.com/blog which is a view showing a list of blogs.  How can I do both?

 


----

 

brendan, fresh-off.com

Creative Direction & Consultation: Web | Print | Brand

 

http://fresh-off.com

hello@...

206.328.1067

 


--
[ Drupal support list | http://lists.drupal.org/ ]

Re: getting block to show up for specific pages and specific node type

by Shai Gluskin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

He Brendan,

You are on the right track. You just have to add some more php to do another test. A slight change in the structure is that you need to make a variable for the display status and then return it only at the end of the whole snippet. When there is only one test, you can just set the status "True" or "False" directly with a return statement that is in the chunk of code as the test itself (that was how your original snippet did it).

Note that I did NOT test the code, so there definitely could be a type in there.

I posted it to a pastebin: http://pastebin.ca/1663597

Shai

Hello,

I found a code snippet on drupal.org that allows a block to be shown only on specific node types when 'Show if the following PHP code returns TRUE' is checked on the Configure Blocks page:

 

-----

<?php
if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
  $thenode = node_load(arg(1));’
  if ($thenode->type == 'blog') {
    return TRUE;
  }
}
?>

-----


this works great, except for that I’d like the block to show for nodes of type “blog” AND also on specific pages – in my case www.mysite.com/blog which is a view showing a list of blogs.  How can I do both?

 


----

 

brendan, fresh-off.com

Creative Direction & Consultation: Web | Print | Brand

 

http://fresh-off.com

hello@...

206.328.1067

 


--
[ Drupal support list | http://lists.drupal.org/ ]


--
[ Drupal support list | http://lists.drupal.org/ ]

Re: getting block to show up for specific pages and specific node type

by brendan, fresh-off.com :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Shai
thanks a lot for your input, it was VERY helpful!  after some messing about with it, here’s what seems to work when I have the “PHP Mode” checked in “Page specific visibility settings” for configuring the block:


<?php

// makes block appear if content type = blog

if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {

  $thenode = node_load(arg(1));

  if ($thenode->type == 'blog') {

    return TRUE;

  }

}

 

//makes block appear if "blog" is in the URL

$url = request_uri();

if (strpos($url, "blog")) {

return TRUE;

}

?>

 

 

 

----

 

brendan, fresh-off.com

Creative Direction & Consultation: Web | Print | Brand

 

http://fresh-off.com

hello@...

206.328.1067

 

 

From: support-bounces@... [mailto:support-bounces@...] On Behalf Of Shai Gluskin
Sent: Monday, November 09, 2009 8:53 AM
To: support@...
Subject: Re: [support] getting block to show up for specific pages and specific node type

 

He Brendan,

You are on the right track. You just have to add some more php to do another test. A slight change in the structure is that you need to make a variable for the display status and then return it only at the end of the whole snippet. When there is only one test, you can just set the status "True" or "False" directly with a return statement that is in the chunk of code as the test itself (that was how your original snippet did it).

Note that I did NOT test the code, so there definitely could be a type in there.

I posted it to a pastebin: http://pastebin.ca/1663597

Shai

Hello,

I found a code snippet on drupal.org that allows a block to be shown only on specific node types when 'Show if the following PHP code returns TRUE' is checked on the Configure Blocks page:

 

-----

<?php
if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
 
$thenode = node_load(arg(1));’
  if (
$thenode->type == 'blog') {
    return
TRUE;
  }
}
?>

-----


this works great, except for that I’d like the block to show for nodes of type “blog” AND also on specific pages – in my case www.mysite.com/blog which is a view showing a list of blogs.  How can I do both?

 


----

 

brendan, fresh-off.com

Creative Direction & Consultation: Web | Print | Brand

 

http://fresh-off.com

hello@...

206.328.1067

 


--
[ Drupal support list | http://lists.drupal.org/ ]

 


--
[ Drupal support list | http://lists.drupal.org/ ]

Re: getting block to show up for specific pages and specific node type

by sebastian-93 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

BTW you should also consider the module: Context, for conditional
blocks, and more.

brendan, fresh-off.com wrote:

> *Shai*
> thanks a lot for your input, it was _VERY_ helpful!  after some messing
> about with it, here’s what seems to work when I have the “PHP Mode”
> checked in “Page specific visibility settings” for configuring the block:
>
>
> <?php
>
> // makes block appear if content type = blog
>
> if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
>
>   $thenode = node_load(arg(1));
>
>   if ($thenode->type == 'blog') {
>
>     return TRUE;
>
>   }
>
> }
>
>  
>
> //makes block appear if "blog" is in the URL
>
> $url = request_uri();
>
> if (strpos($url, "blog")) {
>
> return TRUE;
>
> }
>
> ?>
>
>  
>
>  
>
>  
>
> ----
>
>  
>
> *brendan, fresh-off.com*
>
> Creative Direction & Consultation: Web | Print | Brand
>
>  
>
> http://fresh-off.com
>
> hello@... <mailto:hello@...>
>
> 206.328.1067
>
>  
>
>  
>
> *From:* support-bounces@... [mailto:support-bounces@...]
> *On Behalf Of *Shai Gluskin
> *Sent:* Monday, November 09, 2009 8:53 AM
> *To:* support@...
> *Subject:* Re: [support] getting block to show up for specific pages and
> specific node type
>
>  
>
> He Brendan,
>
> You are on the right track. You just have to add some more php to do
> another test. A slight change in the structure is that you need to make
> a variable for the display status and then return it only at the end of
> the whole snippet. When there is only one test, you can just set the
> status "True" or "False" directly with a return statement that is in the
> chunk of code as the test itself (that was how your original snippet did
> it).
>
> Note that I did NOT test the code, so there definitely could be a type
> in there.
>
> I posted it to a pastebin: http://pastebin.ca/1663597
>
> Shai
>
>     *Hello, *
>
>     I found a code snippet on drupal.org <http://drupal.org> that allows
>     a block to be shown only on specific node types when 'Show if the
>     following PHP code returns TRUE' is checked on the Configure Blocks
>     page:
>
>      
>
>     -----
>
>     <?php
>     if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
>       $thenode = node_load(arg(1));’
>       if ($thenode->type == 'blog') {
>         return TRUE;
>       }
>     }
>     ?>
>
>     -----
>
>
>     this works great, except for that I’d like the block to show for
>     nodes of type “blog” *_AND_* also on specific pages – in my case
>     www.mysite.com/blog <http://www.mysite.com/blog> which is a view
>     showing a list of blogs.  How can I do both?
>
>      
>
>
>     ----
>
>      
>
>     *brendan, fresh-off.com <http://fresh-off.com>*
>
>     Creative Direction & Consultation: Web | Print | Brand
>
>      
>
>     http://fresh-off.com
>
>     hello@... <mailto:hello@...>
>
>     206.328.1067
>
>      
>
>
>     --
>     [ Drupal support list | http://lists.drupal.org/ ]
>
>  
>
--
[ Drupal support list | http://lists.drupal.org/ ]