1

Currently, as standard the url_title field generates the url from the title field. I can then manually change the url_title field for each entry separately, but is it possible to set the url_title field to automatically generate with the title and an additional field for a specific channel?

For example, currently I may have the following fields in a 'Food' channel:

{title}

Pepperoni Pizza

{url_title}

pepperoni_pizza

{restaurant}

Luigi's Smoke House

and I would like to set the url_title to automatically populate with the title and restaurant fields, resulting with:

{url_title}

pepperoni_pizza_luigis_smoke_house

2 Answers 2

3

Have a look at the Magic Fields add-on - it can do this.

0
0

Ammendum: Derek's suggestion seems much more suitable! Thanks for that Derek, I'll look at this module too!!

My origional answer (that I never finished typing)

Its possible, but you'll need to do alot of core and CP hackery to achieve this, the function url_title is in the file `/system/expressionengine/helpers/url_helper.php Line 474 on EE 2.10.1 if your interested. Be wary changing this function though, other diveses and modules use this common function, you'd be better re-implimenting it for the one place you want it.

Also the logic in the CP is not suitable, the current version works as url_title derives from title, so once title field is updated and url_title is blank then update. With your construct there would need to be code that redefines this logic so that if either field is updated and rul_title is blank or matches one or the other fields but not both then.... you see waht I mean???

An Alternative

Could you not handle this another way? Lets say you have a template set up with the route of /resturants/{any} so would pick up the URL /resturants/pepperoni_pizza-luigis_smoke_house. Now lets say you split the 2 fields (lets sayurl_titlefor the Luigi part andfood` as the pizza part) with a dash instead of another underscore so you can seperate the 2 fields, as per the example above.

Then in your template you can easily do this :

<?php 
    //resturant router
    $seg = ee()->uri->segment(2);
    $parts = explode("-", $seg);
?>
{exp:channel:entries dynamic=no url_title="<?php echo $parts[1] ?>" search:food="<?php echo $parts[0] ?>"}
    {!-- ... --}
{/exp:channel:entries}

PHP on INPUT

Another Alternative

Or just use the category system? It's what it's intended for, so Pepperoni Pizza would be the category and Luigi's Smoke House would be the URL title. URL's would look something like : /pepperoni_pizza/luigis_smoke_house or just a permalink to the resturant you want /luigis_smoke_house or all resturants that server pepperoni pizza /pepperoni_pizza/.

Just some suggestions...

2
  • Thanks for the suggestions, I'm going to look into Derek's solution and also try and achieve it another way with the categories, once I have enough rep I'll make sure to give an up vote!
    – JRW
    Commented Jul 9, 2015 at 22:09
  • Well thats much appriciated but you don't worry aboutt the upvotes mate, as long as we have a marked answer it helps other in need :)
    – Blatant
    Commented Jul 10, 2015 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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