ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Alternative to channel_short_name for linking to different entries in different channels

July 27, 2012 2:52pm

Subscribe [1]
  • #1 / Jul 27, 2012 2:52pm

    martinj

    32 posts

    Hi all,

    I’m having real trouble setting up some specific link urls in a template. I’ll try to explain how I need things to work and then what the code looks like with simplified examples.


    1. Requirements

    Entries are stored in 2 Channels: Publications (channel_short_name=“publications”) and Guidance Management and Advice (channel_short_name=“guidance-management-and-advice”)

    There are 2 corresponding Template Groups: publications and guidance-management-and-advice

    The client wants to be able to display teasers for specific entries of their choice on the Publications section index page (i.e. on http://clients-domain-name.org.uk/publications). The entries could be from either channel, Publications or Guidance Management and Advice and links in the teasers should point to the correct Template Group for the entry, either publications or guidance-management-and-advice.

    I’m using a Category Group and Catgeories to allow the client to select which entries appear as teasers, for example Display on Main Section Page: Publications is category 61


    2. Current Template Code (simplified

    {if embed:content_preview == "yes"}
    
    {exp:channel:entries channel="publications|guidance-management-and-advice" status="not closed" category="61" disable="category_fields|member_data|pagination" dynamic="no"}
      <div class="preview-pane{switch="|| preview-pane-last"}">
       <h2>
        <a href="http://{site_url}{channel_short_name}/{if">{title}</a>
       </h2>
    <p>   <div class="preview-container"><br />
        {exp:eehive_hacksaw words="25" append="..." allow="<h3>|<p>"}{gallery-content}{standard_body_content}{/exp:eehive_hacksaw}<br />
       </div><br />
       <br />
        <a href="http://{site_url}{channel_short_name}/{if">Go to page</a><br />
       <br />
      </div><br />
     {/exp:channel:entries}<br />
            <br />
      {/if}


    3. The problem

    The {channel_short_name} variable is causing the problem in the urls. I need the urls for links to entries in the Publications channel to be generated as http://clients-domain-name.org.uk/publications/entry-url-title and entries in the Guidance Management and Advice channel to generated as http://clients-domain-name.org.uk/guidance-management-and-advice/entry-url-title so that the correct template group is used.

    I found out that {channel_short_name} display the channel short name of the current entry (i.e. Publications) which explains why all links are to http://clients-domain-name.org.uk/publications/entry-url-title. I need to use an equivalent variable which shows the Channel Short Name of each individual entry which is displayed as a teaser.

    Really grateful for any and all help with this!

    Thanks

    Martin

    P.S. Moderators, if you feel this is better asked in the Community Help forum please move the post.

  • #2 / Jul 29, 2012 7:43pm

    Lisa Wess

    20502 posts

    Hi, Martin -

    Have you considered using the {comment_url_title_auto_path} variable for building those links instead? It works exactly as you described your need in this case.

  • #3 / Jul 30, 2012 5:24am

    martinj

    32 posts

    Hi Lisa

    Thanks for the reply, I did try {comment_url_title_auto_path} among the many solutions I’ve tried. I found the actual solution to the problem late last night though - someone had created duplicate entries (with slight differences) in the 2 channels. Once I’d cleaned that up the original {channel_short_name} solution worked fine 😊

    Thanks again Lisa

  • #4 / Jul 30, 2012 10:06am

    Lisa Wess

    20502 posts

    Hi, Martin,

    Ouch, I can see how that could be confusing!  I’m glad you figured it out; and now you have another option for future use.

    I hope you have a wonderful Monday, please start a new thread if you need any more assistance.

    Thank you!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases