ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

exp:channel:entries Inside conditionals

November 02, 2011 5:55am

Subscribe [1]
  • #1 / Nov 02, 2011 5:55am

    Un.titled

    34 posts

    Hi,

    I have the following code that I am trying to use to decipher if I am on a category URL or not and show a single entry depending on that URL. The URL structure is just /news or /news/products for example

    {if segment_2 == ""}
        <!-- Any news entry here -->
        {exp:channel:entries channel="news" limit="1"}
    {/if}
    {if segment_2 != ""}
        <!-- Specific category news entry here -->
        {exp:channel:entries channel="news" limit="1" category="{segment_2_category_id}"}
    {/if}
    
    <!-- Code to display the entry stuff here -->
    
    {/exp:channel:entries}

    So I check if segment_2 exists. If it does I pull from the given category using segment_2_category_id from the Low Seg2Cat extension. This works fine. But when I am trying to pull just from the news channel when no segment_2 is specified I get no entries back. Even if I enter a category in the tag that I know has entries I get nothing back. I have also put some debug code just after opening the entries tag and it definitely falls into that piece of code. Any ideas?

    Thanks

  • #2 / Nov 02, 2011 6:04am

    Un.titled

    34 posts

    Apologies, silly mistake from me. The dynamic=“no” flag was the answer. Ooops

  • #3 / Nov 02, 2011 3:35pm

    Kyle Cotter

    730 posts

    Woot! Nice to see you got it fixed up. If you have any more questions, feel free to start a new thread.

    Thanks Un.titled 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases