0

I've created a views page named "Search" with a path of "product-page". Then I created a views block named "Sponsored Ads".

With the "Search" page, I exposed some fields for the filtering, then assigned the "Sponsored Ads" into the region and shows to only page listed "product-page".

I only want to display the "Sponsored Ads" into the "product-page" only, then exclude it from the results with "?" (Eg. /product-page?title=test&field_category_tid=All)

How can I achieve this? Please help...

1

There are actually quite a few methods on how to do this. The method here is quick and easy to do.

Install the devel module (you will uninstall it when your site goes live).

Make sure the block visibility settings is set up to only show on product-page.

Then add this code to your theme's template.php file.

function MYTHEME_block_view_alter(&$data, $block) {
  dpm($block);
  if ($block->module == 'views' && $block->delta == "BLOCK_DELTA") {
    //hide the block
    $params = drupal_get_query_parameters();
    if(count($params) > 0) {
      $data["content"] = FALSE;
    }
  }
}

Change MYTHEME to your theme's name, and clear your cache.

Now you need to change BLOCK_DELTA with the delta of your block. To do that you will need to inspect the dpm output, and find your block, then find the delta of your block.

enter image description here

To further assist you in finding your block delta, you can inspect the block in question in your browser, and look at the id of the block. It will contain the delta as a substring with just the hyphens altered.

enter image description here

My delta is block_content-block so my line of code will be:

if ($block->module == 'views' && $block->delta == "block_content-block") {

When you are done remove the line dpm($block);. You may then uninstall devel module if you wish. This code is a primer and you can adjust it if you need, but as is it will work.

1
  • Wow! Thank you so much J. Reynolds! It works well... Dec 28 '14 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.