0
  • I have content type Ads.
  • I have multiple views pages.
  • I have Views which shows this content type Ads as a view block. Views has multiple block displays, each display for each views pages.

Admin need to choose when adding new node Ads where he want this ad to be shown. He need to choose it from the list. List has for example values X, C, Z

In the Views which shows these Ads as a view block. How to configure contextual filter to check field value? Contextual filter should be set on PHP code - but how to code it?

For example:

  • If field value is X -> show this view block on the path: categories/x (which is Views page, not node!)

** Solution **

I found my own solution to do something like this.

  1. Added custom manual list field type (field_category). For example: X, Y and C
  2. Add view block for each ad category and set filter field_category for each category. (field category = X)
  3. Then in admin/block edit view block: Show block visibility, set PHP format and added this code:

<?php if (arg(0) == 'products' && arg(1) == 'categoryX') { return TRUE; } else { return FALSE; } ?>

As my views pages path are: products/categoryX.

-1

This sounds like a job for Page Manager (part of C-Tools). Create variants that activate on content type AND field value.

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.