Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

When looping through Channel entries, is there a way to provide users with a link they can click on that will take them to that specific Channel entry? I seem to recall seeing some "url" variable available within {exp:channel:entries} tag pair, but can't find it again.

Also, once I'm on that specific Channel entry page, how do I know which entry it is so I can display the rest of the Channel's data?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

If you have an index or listing page, like products, your code maybe like

{exp:channel:entries channel="products" limit="10" orderby="date" sort="desc"}

    <div class="pic-wall"><a href=/product/profile/{url_title}"><img src="/images/product/{product_image_file}" alt="{title}"></a></div>

{/exp:channel:entries}

then on your product profile page, you'd want something like

{exp:channel:entries channel="product" limit="1"}

<h2>{title}</h2>
{product_description}
<hr />
{other_fields}


{/exp:channel:entries}

Additionally, you can use the url_title="{segment_3}" to make sure the record exists, or the if no_results option so that random urls, if generated will result in a 404 call.

The key component is to either use the {url_title}, {entry_id}, {comment_entry_id_auto_path}, or {permalink}. There are a few more options, but they are basically variations of the above for example:

{url_title} will allow you to custom create the path to the entry like

<a href="{domain}/products/detail/{url_title}" title="{title}">{title}</a>

or you could use {url_title_path}. {url_title_path} assumes you've completed the details in channel profiles, when you were setting things up, so if you said the default path for products was products/details it will use that, but if you said it was products/index then it would have the wrong path.

I tend to use the {url_title} because I like the flexibility, one of the other developers I work with prefers using the {url_title_path} option. But both will create a link, so that you can design a template with detail specific fields.

Take a look at http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#parameters to see all the various parameter options available to you.

share|improve this answer
    
OK - I understand url_title now. What I don't understand is the "profile page." How does it know which entry it's trying to display? Does it make certain assumptions based on the URL? –  ExpressionEngineNewbie Dec 26 '12 at 1:15
    
No the {url_title}, is unique per section or you can use the {entry_id}, but the {url_title} is more SEO and user friendly. It would change <a href="{domain}/products/detail/{url_title}" title="{title}">{title}</a> to <a href="http://mydomain.org/products/profile/cat_knitting_tee_shirt" title="Cat Knitting Tee">Cat Knitting Tee</a> –  nonprofit_tech Dec 26 '12 at 4:30
add comment

My preferred method is to use {comment_url_title_auto_path}. I find that this is the most future proof method since if your urls change in the future for some reason then you only need to make a change in the url settings for that specific channel and not throughout all of your templates. In your specific channel go to admin > channel Preferences > channel name and be sure to fill out the comment page url with the segment of where that channel should appear. For example if it's for your blog page which has a url like this domain.com/blog/url_title then in that setting you would put blog.

share|improve this answer
    
We always create a variable, called {domain} in the path.php or index.php file using global variables, that way, this <a href="{domain}/products/detail/{url_title}" title="{title}">{title}</a> will work. That maybe because we frequently use the old method of creating subsites, instead of MSM. Though most of the developers I know use relative paths. –  nonprofit_tech Dec 26 '12 at 16:02
    
Why {domain}? Why not just use {site_url}? –  ExpressionEngineNewbie Dec 26 '12 at 22:46
    
It's part of a grouping of global variables that we test against. I can't recall why we first needed it, but {site_url} was returning current url, and we had need for if these 3 criteria were match, the link would point to a sub site domain, like mydomain2.org, even if current domain was domain.org. –  nonprofit_tech Dec 27 '12 at 5:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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