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 problem}

March 23, 2009 8:11am

Subscribe [5]
  • #1 / Mar 23, 2009 8:11am

    designworks.hk

    12 posts

    I have a problem on using if no_result..see if anyone can help..

    {exp:weblog:entries weblog="vphk_articles"  category="{category_id}" url_title="{segment_2}" dynamic="on" }
    {if no_results}
    <h1>404?<h1>
    {/if}
    
    <h1>{title}</h1>
    {article_content}
    {/exp:weblog:entries}

    I randomly type something in segment_2, but it just empty, i jsut can’t get the 404? shown. It just keep empty in that div.
    Can anybody help?

  • #2 / Mar 23, 2009 8:28am

    Steve Abraham

    149 posts

    Hi,

    Just as a test - can you try changing dynamic to “off”, and see if you still get the same problem?

    Cheers,
    Steve.

  • #3 / Mar 23, 2009 11:28am

    Sue Crocker

    26054 posts

    Where are you getting category_id from? What does your URL look like?

  • #4 / Mar 23, 2009 11:51am

    designworks.hk

    12 posts

    Hi steve, Thanks! but dynamic off doesn’t help

    Hi Sue , Thanks!
    Here is more of my code

    {exp:weblog:categories weblog="vphk_articles" style="linear" }
    {if segment_1 == category_url_title}
    
    {exp:weblog:entries weblog="vphk_articles"  category="{category_id}" url_title="{segment_2}" dynamic="on" }
    {if no_results}
    <h1>404?<h1>
    {/if}
    <h1>{title}</h1>
    {article_content}
    {/exp:weblog:entries}
    
    {/if}
    
    {/exp:weblog:categories}

    my URL is like that:
    domain/index.php/(category_url_title)/{url_title)/

    I have the correct category_url_title and url_title, the correct article will be shown. But If I had a correct category_url_title, but incorrect url_title
    it just show empty, instead of 404.

    Thanks !!

  • #5 / Mar 23, 2009 12:01pm

    hothousegraphix

    851 posts

    Have you set up a 404 page? If so, maybe try

    {if no_results}{redirect="404"}{/if}
  • #6 / Mar 23, 2009 12:48pm

    designworks.hk

    12 posts

    setting up the 404 page, but still no luck~~ >.<

  • #7 / Mar 23, 2009 10:06pm

    Greg Aker

    6022 posts

    where are you grabbing {category_id} from?

  • #8 / Mar 24, 2009 1:51am

    designworks.hk

    12 posts

    it is under {exp:weblog:categories}
    Therefore there is a {category_id}

    Thanks for all of your help, but I tried another methodology with embed variable through sub templates. Which do the same and no_results seems fine after I only use {exp:weblog:entries} without {exp:weblog:categories} , and with the embed variable instead of {category_id} and {url_segment}.

    I dont’ know y, but it is now working~^^

    Thanks!

  • #9 / Mar 24, 2009 2:27am

    John Henry Donovan

    12339 posts

    Glad you got it working. Feel free to post again if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases