ExpressionEngine: Single entry template
This is actually a pretty easy to shore up issue. What you have going on is that line 5 of your code has no way to tell if it should limit the entry information. With dynamic='no'
, you've said "EE, you don't need to use the URL here to figure out what entries to limit this by"
My suggestion would be the following code:
{if segment_2 == ""} {exp:channel:categories category_group="1" style="linear" dynamic="no"} <div class="card-list tab" id="{category_url_title}"> <h2 class="category-title">{category_name} Credit Cards</h2> <div class="cards"> {exp:channel:entries channel="credit_cards" category="{category_id}" dynamic="no" disable="category_fields|member_data|pagination|trackbacks"} <article> <h4><a href="{url_title_path='credit-cards'}">{title}</a><span class="web-exclusive">MBNA Website Exclusive</span></h4> <ul> <li class="col-img"> <a href="{url_title_path='credit-cards'}"><img width="116" height="84" alt="MBNA Platinum Credit Card" src="../lib-ui/img/cards/core/core_116x84/mbna_platinum_card_116x84.png"></a> </li> <li class="col-bt">{balance_transfer_rate}</li> <li class="col-purchases">{purchases_rate}</li> <li class="col-features">{key_features}</li> <li class="col-apply"> <a rel="blank" class="btn btn-success" href="{apply_url}"> Apply Now<span class="hide"> for the {title}</span> </a> <a class="cta" href="{url_title_path='credit-cards'}"> Learn more<span class="hide"> about the {title}</span> </a> <label class="mbna-credit-card checkbox" for="compare_1"> <span tabindex="0"> <input type="checkbox" value="mbna-credit-card" id="compare_1"> </span> <span class="hide"> Add the {title} to </span>Compare </label> </li> </ul> <p class="rep-ex">{representative_example}</p> </article> {/exp:channel:entries} </div> </div> {/exp:channel:categories}{/if}{if segment_2} {exp:channel:entries channel="credit_cards" limit="1" disable="category_fields|member_data|pagination|trackbacks"} <article> <h4><a href="{url_title_path='credit-cards'}">{title}</a><span class="web-exclusive">MBNA Website Exclusive</span></h4> <ul> <li class="col-img"> <a href="{url_title_path='credit-cards'}"><img width="116" height="84" alt="MBNA Platinum Credit Card" src="../lib-ui/img/cards/core/core_116x84/mbna_platinum_card_116x84.png"></a> </li> <li class="col-bt">{balance_transfer_rate}</li> <li class="col-purchases">{purchases_rate}</li> <li class="col-features">{key_features}</li> <li class="col-apply"> <a rel="blank" class="btn btn-success" href="{apply_url}"> Apply Now<span class="hide"> for the {title}</span> </a> <a class="cta" href="{url_title_path='credit-cards'}"> Learn more<span class="hide"> about the {title}</span> </a> <label class="mbna-credit-card checkbox" for="compare_1"> <span tabindex="0"> <input type="checkbox" value="mbna-credit-card" id="compare_1"> </span> <span class="hide"> Add the {title} to </span>Compare </label> </li> </ul> <p class="rep-ex">{representative_example}</p> </article> {/exp:channel:entries} {/if}
Mind you, this isn't 100% accurate, as I stripped out your exp:channel:categories
tag, but this should get you a result that limits based on a shortened URL like you've specified.
So how do I get it to use this template file instead for a single entry?
Instead of:
{url_title_path='credit-cards'}
Use
{title_permalink="credit-cards/single"}
There are two primary ways you can use the template 'credit-cards/single' for the VISA credit card category entry.
First Option
'credit-cards/index' template would have:
{if segment_2 != ""} {embed="credit-cards/single" entry_id="{entry_id}"}{/if}
'credit-cards/single' template would have:
<h1>Credit Card Page</h1>{exp:channel:entries channel="credit_cards" limit="1" entry_id="{embed:entry_id}"}{if no_results} {redirect="404"}{/if}... your code ...{/exp:channel:entries}
Second Option
Rename 'credit-cards/single' to 'credit-cards/company' (or something more SEO relevant) and use it the default EE way.
'credit-cards/index' template would stay the same.
'credit-cards/company' template would have:
<h1>Credit Card Page</h1>{exp:channel:entries channel="credit_cards" limit="1" entry_id="{entry_id}"}{if no_results} {redirect="404"}{/if}... your code ...{/exp:channel:entries}
In this second option the url would be site.com/credit-cards/company/visa-credit-card
I hope that helps. Let me know if I've misunderstood anything.