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.

if no_results does not send to my 404 page

November 25, 2014 7:35am

Subscribe [2]
  • #1 / Nov 25, 2014 7:35am

    worfoual's avatar

    worfoual

    61 posts

    I have a page who is showing the listing of all my news items and you can also “filter” the news items by category.
    In this page I also use the add-on switchee. Here is my code, I delete all the div and span to make it smaller:

    {exp:switchee variable="{segment_3}" parse="inward"}
    
    
    {!-- --------------------------------- ALL NEWS ITEMS ------------------------------  --}
    {case value="#^P(\\\\d+)$#|''|tag"}
    
    {!-- tag is my Category URL Indicator --}
    
    {exp:channel:categories channel="ch_nieuws" style="linear"}{if active} :: {category_name}{/if}{/exp:channel:categories}
    
    
    {exp:channel:entries channel="ch_nieuws" disable="member_data" pagination="bottom" limit="7"}
    
    <!-- 1 nieuws item-->
    
    {categories style="linear" backspace="2"}{category_name}, {/categories}
    
    
    {title}
    {nieuws_teaser} <a href="http://{title_permalink=actueel/nieuws}">READ MORE</a>
    
    <!-- einde 1 nieuws item-->
    
    
    <!--  PAGINATION   -->
    here is the pagination code 
    <!--  E.O. PAGINATION   -->
    
    {/exp:channel:entries}
    
    
    <!-- ============= SIDE BAR LEFT ================================ -->
    filter berichten
    
    <!-- filter per category -->
    
    <form name="catmenu" action="">
        <select name="selcat" class="droptagstyled" >
            <option value="">Selecteer tag</option>
            {exp:channel:categories channel="ch_nieuws" show_empty="no" style="linear"}
                <option value="{path='actueel/nieuws'}">{category_name}</option>
            {/exp:channel:categories}
        </select>
    </form>
    
    <!-- e.o. filter per category -->
    
    
    <!-- ============= EINDE SIDE BAR LEFT ================================ -->
    
    
    {/case}
    
    {!-- --------------------------------- 1 SELECTED NEWS ITEM ------------------------------  --}
    
    {case default="Yes"}
    
    
    {exp:channel:entries channel="ch_nieuws" disable="member_data|paginate" limit="1" url_title="{segment_3}" require_entry="yes"}
    
    {if no_results} {redirect="404"} {/if}
    
    {entry_date format="%d-%m-%Y"} {categories style="linear" backspace="2"}{category_name}, {/categories}
    
    
    <h1>{title}</h1>
    
    {nieuws_inleiding}
    
    {if nieuws_foto != "" }
    {nieuws_foto}
    {/if}
    
    
    {nieuws_tekst}
    
    
    {/exp:channel:entries}
    
    
    {/case}
    
    {/exp:switchee}
    
    
    {embed=includes/footer}

    Everything is working as expected,
    in this url type: .../actueel/nieuws I get all the news items
    in this url type: .../actueel/nieuws/tag/press I get all the news item from category press

    If I clic on the READ MORE from on news item i also get everything just fine, something like that:
    ../actueel/nieuws/my-first-news and I see the “detail” of that news item.

    But let’s say I change manually the last segment (my-first-news) in something that doesn’t exist, for example blablabla, then I should expect to be redirect to my 404 page. But it is not the case, I just get a blanco page.

  • #2 / Dec 03, 2014 1:05pm

    Giraffentoast

    150 posts

    Works for me.

    Seeing how you got a whole lot of markup in that template (some of which seems redundant), I’d recommend deleting all that, just leaving the channel entries tag plus conditional. See if that works, then add the rest of the code step by step to see where the problem is.

    Also, add dynamic=“no” to make sure EE is looking in the right channel. 😊

  • #3 / Dec 05, 2014 7:54am

    worfoual's avatar

    worfoual

    61 posts

    Thanks for your help.
    I found the problem, when you use switchee the {if no_results} does not work, you need to use this one {if switchee_no_results}.

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

ExpressionEngine News!

#eecms, #events, #releases