2

I have used channels for different sections of a website, however I have noticed that if a channel entry has the same URL title of another entry in a different channel the url_title field is not automatically incremented and the first entry results in a 404 error. Is there a way to automate this? This occurs even if a category url title is the same as a entry.

For example; I have 2 channels, your-life and a-z; I have a category called contraception in your-life and an entry in a-z named contraception, both have the url_title "contraception".

When I leave them both at contraception, the SQL for the your-life category is as below, and the entries in this category do not appear:

SELECT DISTINCT(t.entry_id) FROM exp_channel_titles AS t
LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id
LEFT JOIN exp_channel_data AS wd ON t.entry_id = wd.entry_id
LEFT JOIN exp_members AS m ON m.member_id = t.author_id
INNER JOIN exp_category_posts ON t.entry_id = exp_category_posts.entry_id
INNER JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id
WHERE t.entry_id !='' AND t.site_id IN ('1') AND t.entry_date < 1403708810  AND (t.expiration_date = 0 OR t.expiration_date > 1403708810) AND t.channel_id = '17' AND t.url_title = 'contraception' AND exp_categories.cat_id = '35' AND t.status = 'open'
ORDER BY t.sticky desc, wd.field_id_97 asc, t.entry_id asc
LIMIT 0, 100
#APP/modules/channel/mod.channel.php L:277  Channel::build_sql_query()

and if I change the url_title for the a-z entry to "contraception1", the SQL is as below, and the entries in the category are shown

SELECT DISTINCT(t.entry_id) FROM exp_channel_titles AS t
LEFT JOIN exp_channels ON t.channel_id = exp_channels.channel_id LEFT JOIN exp_channel_data AS wd ON t.entry_id = wd.entry_id LEFT JOIN exp_members AS m ON m.member_id = t.author_id INNER JOIN exp_category_posts ON t.entry_id = exp_category_posts.entry_id
INNER JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id
WHERE t.entry_id !='' AND t.site_id IN ('1')  AND t.entry_date < 1403709091  AND (t.expiration_date = 0 OR t.expiration_date > 1403709091) AND t.channel_id = '17' AND exp_categories.cat_id = '35' AND t.status = 'open'
ORDER BY t.sticky desc, wd.field_id_97 asc, t.entry_id asc
LIMIT 0, 100
#APP/modules/channel/mod.channel.php L:277  Channel::build_sql_query()

EDIT//

{if embed:layout == 'Horizontal'}
    <section class="container listing-block">
        <div class="col-xs-offset-1 col-xs-10">
        {exp:channel:entries channel="{embed:segment_1}" category="{embed:category_id}" orderby="yh_order" sort="asc"}
            <article class="listing">
                <div class="main-image">
                    {yh_images}
                    {yh_images:yh_listing_image}
                    <img src="{path}_listing/{filename}.{extension}" alt="{title}">
                    {/yh_images:yh_listing_image}
                    {/yh_images}
                </div>
                <div class="listing-inner">
                    <h2><a href="{title_permalink='{embed:segment_1}/single'}">{title}</a></h2>
                    <a class="btn btn-primary pull-right" href="{title_permalink='{embed:segment_1}/single'}">View more</a>

                </div>
            </article>
        {/exp:channel:entries}
        </div>
    </section>
{if:elseif embed:layout == 'Vertical'}
    {exp:channel:entries channel="{embed:segment_1}" category="{embed:category_id}" orderby="yh_order" sort="asc"}
    <section class="container pageBlock">
        <div class="col-xs-offset-1 col-xs-10  panel pageBlock-{yh_colour}">
            <h1 class="text-center">
                {yh_icon}
                <img src="{path}_button/{filename}.{extension}" alt="{title}">
                {/yh_icon}
                {exp:filthy}{title}{/exp:filthy}
            </h1>
            <article class="panel-body">
                {yh_leader_text}
                <a href="{title_permalink='{embed:segment_1}/single'}" class="center-block btn btn-{yh_colour} filthy">Read more</a>
            </article>
        </div>
    </section>
    {/exp:channel:entries}
{if:elseif embed:layout == 'Icons'}
    {exp:channel:entries channel="{embed:segment_1}" category="{embed:category_id}" orderby="yh_order" sort="asc"}
        {if count == 1}
        <section class="container {if total_results % 3 == 0}fundraise-links{if:elseif total_results % 5 == 0}home-links{if:else}home-links join-in-links{/if}">
            <div class="row col-xs-offset-1 col-xs-10">
                <ul>
        {/if}
                    <li class="text-center {yh_colour} fader">
                        <div>
                            <a href="{title_permalink='{embed:segment_1}/single'}">
                                {yh_icon}
                                <img src="{path}_button/{filename}.{extension}" alt="{title}">
                                {/yh_icon}
                                <h2 class="filthy">{exp:filthy}{title}{/exp:filthy}</h2>
                            </a>
                        </div>
                    </li>
        {if count == total_results}
                </ul>
            </div>
        </section>
        {/if}
    {/exp:channel:entries}
{/if}
  • All your entries uses the same template_group/template?! – Robson Sobral Jun 24 '14 at 14:42
  • I'm using channel_name/template – Steven Lavine Jun 25 '14 at 14:14
  • I'm sorry, but I can't understand how you're getting 404 if the templates are different. Can you, please, add a sample of code which creates the links? Or give us more information? – Robson Sobral Jun 25 '14 at 14:45
  • For example; I have 2 channels, your-life and a-z; I have a category called contraception in your-life and an entry in a-z named contraception, both have the url_title "contraception" – Steven Lavine Jun 25 '14 at 15:08
  • 1
    I'm sorry about the delay. I had some stuff to deal with. Please, take a look at the updated answer of Mike. The dynamic parameter is what you're looking for. – Robson Sobral Jun 27 '14 at 19:03
8

EE has always maintained a unique entry id, but only unique url titles within a given channel. There is no way that I know of to force unique url titles across all channels.

This usually isn't an issue so long as you are specifying channels in your template code.

Incidentally this is why EE uses a /category/ segment when using category url titles - that's the trigger to know that what follows is a category url title and not an entry url title.


But it happens that you're overriding the default behavior. Take a look at this schema.

The segment used for the category URL indicator is the same used for entry url_title. If you want to override the URL behavior of EECMS, remember to set the dynamic parameter to no.

Plus, you're sending the IDs of the categories as embed variables, so they don't even need to be picked from the URL! From the docs:

Using this parameter will automatically cause ExpressionEngine to ignore any category information specified via the URL. For instance, if you are on a “category page” (e.g. a /C13/ segment in the URL) that will be completely ignored in favor of whatever you have specified via the parameter.

Take some time to study how the URL are used by EECMS.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.