Hey guys,
I am looking for how to link to the “pretty url” of a news entry. I have tried {permalink} and {page_url} both do not do what I want. Here is what my listing template looks like currently:
{exp:channel:entries channel="news|events" limit="10" dynamic="off" pagination="bottom" orderby="date"}
<article>
<header>
<h2><a href="http://{page_url}" title="{title}">{title}</a></h2>
<div class="post-meta">
Posted on {entry_date}
</div>
</header>
</article>
{/exp:channel:entries}I am wanting the place that has {page_url} to create a URL like this:
http://www.mysite.com/channel/My-Cool-Title
Thanks for your help.
Greg
There are a number of linking variables available in the channel://entries tag pair, I think you’re after either title_permalink or url_title_path which do exactly the same thing.
Thanks again for your help, but I am running into issues where i can’t dynamically change anything. For example, I have the listing template mentioned above and want to use that for 2 separate channels called news and events. So when I use just title_permalink it returns www.mysite.com/index.php/my-entry-title instead of www.mysite.com/index.php/channel/my-entry-title
I don’t want to have to have a separate template for every channel that I list, so how do I dynamically place the channel shortname within title_permalink=’channel/news’, for example I’ve tried the following:
<a href="{title_permalink='channel/{short_name}'" title="{title}">Sorry for the confusion I just can’t seem to figure out dynamic variables within expression engine. Thanks again.
Well, lets back up a bit.
Do you have a grasp on what channels are for and what templates are for?
You don’t specify a channel name in a link. Channels just hold content, templates are how the content is pulled to a rendered page and so it’s template names that get specified in a link:
IE:
<a href="http://{url_title_path=template-group/template-name}">{title}</a>You may happen to have both a channel and template group named ‘news’ - but that would just be a circumstance.
Now you are specifying multiple channels in your entries tag. If your need is to point the result link to a different template based on the channel it comes from you can do that, and the approach is covered here (see the 3 Weblogs, 1 Weblog:Entries Tag with Weblog-Specific Links - just mentally replace ‘weblog’ with ‘channel’ as the example was done in EE1 and EE2 uses channel instead)
http://www.train-ee.com/courseware/free-tutorials/comments/working-with-combined-weblogs
Well, lets back up a bit. Do you have a grasp on what channels are for and what templates are for? You don’t specify a channel name in a link. Channels just hold content, templates are how the content is pulled to a rendered page and so it’s template names that get specified in a link: IE:You may happen to have both a channel and template group named ‘news’ - but that would just be a circumstance. Now you are specifying multiple channels in your entries tag. If your need is to point the result link to a different template based on the channel it comes from you can do that, and the approach is covered here (see the 3 Weblogs, 1 Weblog:Entries Tag with Weblog-Specific Links - just mentally replace ‘weblog’ with ‘channel’ as the example was done in EE1 and EE2 uses channel instead) http://www.train-ee.com/courseware/free-tutorials/comments/working-with-combined-weblogs<a href="http://{url_title_path=template-group/template-name}">{title}</a>
If you are wanting one single entry template to display the result no matter what channel it comes from just make sure the channel:entries tag on that template also has both channels specified, and link to it using either the title permalink or url_title_path variable and it should work.
just make sure the channel:entries tag on that template also has both channels specified, and link to it using either the title permalink or url_title_path variable and it should work.
I have done this, but just for clarity here is my listing template I am using:
{exp:channel:entries channel="news|events" limit="10" dynamic="off" pagination="bottom" orderby="date"}
<article>
<header>
<h2><a href="http://{title_permalink}" title="{title}">{title}</a></h2>
<div class="post-meta">
Posted on {entry_date}
</div>
</header>
</article>
{/exp:channel:entries}But when I go to click the links they come back as:
http://testaqq.nana.com/index.php/christmas-partyNotice, the channel is missing.
I don’t think it’s the code becuase the code itself is executed as expected per the documentation. I think it may be the way that I am setting it up. I followed this tutorial for creating a blog (http://shapingthepage.com/journal/how-to-build-a-simple-tumblr-blog-with-expressionengine)
So my page has a conditional statement like so:
{if segment_1 == "news-events" AND segment_2 == ""}
1
{embed="blog/listing"}
{if:elseif segment_1 == "news" AND segment_2 != ""}
2
{embed="blog/article"}
{if:else}
3
{body}
{/if}Am I going about this the wrong way, is there a better approach?
Personally I’d recommend starting simpler until you get a better feel for how EE works. Segments and conditionals and combined templates are a great next-step once you have the basics down. I’d start with separate templates for the listing and detail views before trying to combine them all.
You aren’t specifying a path with your title_permalink variable, so ee is just appending the url title of the entry onto the sites root domain. If you need other values in the segment_1 postion you need to specify them in the title_permalink variable.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.