Exclude entry based on segment I am trying to exclude the current entry in a "Recommended Reading" section which works at level 1 with the ID tag, but I also need it to do the same at level 2 (children). 

 `{% for entry in craft.entries.section('Thunder').level(1).id('not '~entry.id).limit(3).order('RAND()') %}`


The level 1 entry is the Article and the level 2's are the Chapters. The recommended reading section displays other Articles and should therefor exclude the level(1) article also when viewing the Chapters. 

Should I use craft.request.getSegment(2) to exclude the current entry, but how do you write that conditional statement?

Url structures are:

/site/article
/site/article/chapter


Section: Structure
No matter how many levels there are in your structure ancestorOf will fetch level one entry. entry.parent could be used but covers only one level up.

{% set excludeEntry = entry %}
{% if entry.level &gt; 1 %}
    {% set excludeEntry = craft.entries.ancestorOf(entry).level(1).first() %}
{% endif %}

{% for entry in craft.entries.section('Thunder').level(1).id('not '~excludeEntry.id).limit(3).order('RAND()') %}
...
{% endfor %}