Linking to articles using the article’s weblog in ExpressionEngine
I have an index template that displays articles from several sections (weblogs), but when linking to an article we must specify the template_group and template to use. I have different template groups for each section, and want to use them as they define the article’s URL. However, the obvious way of using {title_permalink="{weblog_short_name}/index"} doesn’t work (although we can use {segment_#} like this).
You can do this by passing the {weblog_short_name} and {entry_id} of each article to an embedded template using embedded variables:
You can do this by passing the {weblog_short_name} and {entry_id} of each article to an embedded template using embedded variables:
<!-- the index template that calls the embedded template --> {exp:weblog:entries weblog="not pages" orderby="date" sort="desc" limit="10" disable="categories|comments|member_data|pagination|trackbacks"} <div class="article"> {date_heading}<h3 class="date">{entry_date}</h3>{/date_heading} <h3>{weblog}</h3> <h2 class="title"><a href="{target_url}" title="{target_title}">{title}</a></h2> {summary} <!-- the next line embeds the template and sets the variables --> <p><a href="{embed="snippet/body-hp-link" the_weblog="{weblog_short_name}" the_entry_id="{entry_id}"}">Read more</a> or comment…</p> </div>{/exp:weblog:entries}
<!-- the embedded template --> {exp:weblog:entries weblog="{embed:the_weblog}" entry_id="{embed:the_entry_id}" dynamic="off" disable="categories|comments|member_data|pagination|trackbacks"}{title_permalink="{embed:the_weblog}/index"}{/exp:weblog:entries}