Category ID
ExpressionEngine 1.x, ExpressionEngine 2
Back to this add-on's main page
View Other Add-ons From Laisvunas
Problem with no_results in channel:entries
Bug Report
akrug23
|
Posted: 12 May 2011 11:49 AM |
|
|
|
I am using your addon. But I think I have found a bug in it. I have a page that displays projects based on categories. I am using your add-on to figure out which category was selected from the url. The problem that I am running into is that if I use the channel entries tag and there are no results the no_results conditional does not work.
Everything works if I take it out of the category_id tag pair. Is there a work around?
Here is how my code is (simplified)
{exp:category_id category_group="1" category_url_title="{segment_3}" parse="inward"}
{embed="embeds/html_header" page_title="Projects"}
{embed="embeds/header"}
{exp:channel:entries channel="projects" status="not closed" limit="4" paginate="both" category="{category_id}"} {if no_results} <div id="projectList"> <h1>No Results</h1> </div> {/if} {paginate} <div id="projectPageLeft">{pagination_links}</div> {/paginate} <div id="projectList"> <div class="projectEntries"> <h2><a href="{title_permalink}">{title}</a></h2> <div class="date">{entry_date format="%F %j%S, %Y"}</div> {project_excerpt} </div>
</div> {/exp:channel:entries} </div> </div> {embed="embeds/footer"}
{/exp:category_id}
|
|
|
Laisvunas
|
Posted: 12 May 2011 03:20 PM |
# 1
|
|
Developer
|
Hi,
There is no bug; it is how exp:channel:entries tag works. For some reason ExpressionEngine thinks that in this situation there is “a result” and evaluates “if no_result” conditional as FALSE.
In such situations I use Entries Number plugin to calculate number of entries:
{exp:entries_number channel="projects" status="not closed" category="{category_id}" parse="inward"} {if entries_number == 0} <div id="projectList"> <h1>No Results</h1> </div> {/if}
{if entries_number > 0} {exp:channel:entries channel="projects" status="not closed" limit="4" paginate="both" category="{category_id}"} {paginate} <div id="projectPageLeft">{pagination_links}</div> {/paginate} <div id="projectList"> <div class="projectEntries"> <h2><a href="{title_permalink}">{title}</a></h2> <div class="date">{entry_date format="%F %j%S, %Y"}</div> {project_excerpt} </div>
</div> {/exp:channel:entries} {/if} {/exp:entries_number}
|
|
|
sk2014
|
Posted: 17 September 2014 03:34 PM |
# 2
|
|
|
Dear Laisvunas.
This addon works like a charm. I was pulling my hairs out for this problem for few days.
However I have a similar situation like mentioned in the above post. The addon works perfect to check the category id and shows the entries for that category, and the page is properly redirected to “404” when the category doesn’t exist.
I want to output “there are no entries in this category” when there is none. I am trying to use the if no results conditional. This is the part not working for me. The code as follows:
{exp:category_id category_group="6" category_url_title="{segment_3}" parse="inward"}
{if category_id != "" }
{exp:low_alphabet:entries channel="movie_index" category="{last_segment_category_id}" orderby="title" sort="asc" auto-limit="yes" require_entry="yes" disable="member_data|pagination"}
<ul id="mi_list"> <li><a href="{title_permalink=">{title}</a></li> </ul>
{if no_results} <h3>There are no entries in this category.</h3> {/if}
{/exp:low_alphabet:entries}
{if:else} {redirect="site/page_not_found"} {/if}
{/exp:category_id}
I see you mentioned about entries number addon. My question is whether the entries addon tag will work inside the category id tag in the above situation. Please give me some example code if it can. Thank you.
|
|
|