Show blocks based on parent URL context We are looking for a way to show banners on pages based on their URL parent. There are multiple banners in use, and each page should display a banner based on its parent page. We want to build this into the theme, if at all possible.

So, for the Programs section, the Programs banner should display. However, within Programs there are named Programs with their own banners, such as "Great Program" and "Program For Winners" which each have their own sub-pages. When on those sub-pages, we want only the banner for the specific program to show. 

/programs - Show Programs banner (top-level parent)

/programs/all - Show Programs banner

/programs/great-program - Show Great Program banner (second-level parent)

/programs/great-program/about-great-program - Show Great Program banner 

Note: I'm using D7, and probably using blocks, maybe Views. Open to all suggestions.
If you'd implement those banners via blocks, then you might be able to get it to work using the Rules block visibility module. Here is a quote from its project page:


  The Rules block visibility module allows Rules components to be used to control block visibility. This provides Drupal administrators and developers extreme flexibility in controlling when blocks should be displayed on their websites, in addition to the default visibility options provided by Drupal.
  
  The general idea is that if you can do it with Rules, you can use it to control block visibility, so the possibilities are limitless.
  
  Need to show a block only for users registered more than a month ago?
  
  Perhaps you have a block that must be shown only between 8am-5pm on weekdays?
  
  What about displaying or hiding a block based on current weather conditions?
  
  All of this can be done by using Rules block visibility.


With that, and as per the "if you can do it with Rules, you can use it to control block visibility" above, you've reduced your question to making Rules intercept the various URLs corresponding to each of those banners.

If you're not familiar with how to do that with Rules, then have a look at my answer to the question "How to make the permissions of a module more granular?" (and pay attention to the regex-expression included in the sample rule I included there).