Display similar content type nodes as current node

   comments
Share

In this blog, we are going to explore the trick about how to display all nodes of same content type as the current node using Views.

We can use contextual filter to get this structure with Views.

Let's follow the following simple steps to achieve it:---

  1. Create a block view for any content type which listing you want to show.
  2. Format: no any special setting.

    View_1

  3. Expand the 'Advanced' options on the right side and Click 'Add' next to 'Contextual Filters'.

    click-advanced

  4. Enter 'Type' in the search box filtering the results to just 'Content: Type' then check this box and click 'Apply (all displays)' button.

    views-2

  5. Click on 'Provide default value' next to When the filter value is NOT available
  6. Select PHP code under Type and enter below code under PHP contextual filter code

    $node = node_load(arg(1)); return $node->type;

  7. click 'Apply (all displays)' button.

    views_3

  8. Now assign this views on any page and check your result.

    block_region_settings

Add new comment