Search code examples
phpexpressionengine

Expression engine exclude entry of currently viewed page from "archive" section


I'm in the need of showing a News page with a subsequent archive section. I would like to exclude the currently viewed entry from the archive section.

This is my Expression Engine/PHP code so far:

<article  class="d1-d8 tp1-tp4 ml-all mp-all">
         {exp:channel:entries channel="news" limit="1" status="open" sort="asc"}
              <h2><a href="#">{title}</a></h2>
             <p>{testo_notizia}</p> 

Then I assign the above entry_id in a php variable

 <?php $entry_id = '{entry_id}'; ?>

And continue with my Expression Engine code

{/exp:channel:entries}
             <h2>Archivio news</h2>

<?php echo $entry_id; ?>   //THIS SHOWS CORRECTLY


  {exp:channel:entries channel="news" entry_id="not <?php echo $entry_id; ?>" status="open" sort="asc" dynamic="no"} 
//THE FILTER IS NOT WORKING/EXCLUDING THE PREVIOUS ENTRY_ID FROM THE LISTING
    <div class="titoli-notizie">
                  <h3><a href="{url_title_path='/news/view'}">{title}</a></h3>
                  </div>
             {/exp:channel:entries}
             </article> 

Solution

  • I solved by using the special url_title="not {segment_2}" instead of relying on php variables, which is a much sweeter option in my opinion.