1

Trying to link to pages as "Related Articles". Here is my code. The template is used to display the articles. My text, "Related Articles" is not showing either. Using EE 2.7. Any help is appreciated.

    <div class="sixteen columns mainContent redTop boxShadow">
    {exp:channel:entries category="{embed:pageCat}" limit="1"}


        <div class="text eleven columns alpha">

            <h1 class="blue borderBottom">{news_title}</h1>
            <span class="date orange">{entry_date format="%F %j, %Y"}</span>
            {if news_image}
                {news_image var_prefix="file"}
                <div class="pageImage right"><img src="{file:url}" alt="{file:alt_text}"></div>
                {/news_image}
            {/if}
            {news_text}

            {related_articles}
                {if related_articles}
                Related Articles:
                <ul>
                {/if}
                <li><a href="{site_url}/news/industry/{last_segment}">{related_articles:title}</a></li>
                {if related_articles:count == related_articles:total_results}
                </ul>
                {/if}
            {/related_articles}             

        </div>

        {embed="includes/zipSearch"}

<div class="five columns sidebar right alpha">
    <div class="box boxShadow blueTop sideNav">{exp:channel:entries category="11"}
        <h4>Spread Awareness:</h4>
        {!--exp:navee:nav nav_title="main-site-nav" selected_class="selected"  parent_selected_class="selected" start_nav_with_kids_of_selected="true" start_nav_from_parent="true" start_nav_from_parent_depth="1" only_display_children_of_selected="true"--}
        {exp:navee:nav nav_title="main-site-nav" selected_class="selected" start_node="/spread-awareness/" start_nav_from_parent_depth="2" only_display_children_of_selected="true"}
    </div>

    {if "{related_video:count}" != ""}
    <div class="box boxShadow orangeTop">
        <div class="youtubeLink">
            <iframe width="420" height="315" src="//www.youtube.com/embed/{related_video}{related_video:video}{/related_video}" frameborder="0" allowfullscreen></iframe>
        </div>
    </div>
    {/if}
</div><!--end sidebar-->
    {/exp:channel:entries}
    </div><!--end mainContent-->
2
  • I'm no expert, but it seems you're using the {if} conditional wrong. I'm not sure {if related_articles} is proper syntax, and I see you are using {/if} followed by another {/if}. In my experience, if plain text isn't being rendered within a variable tag pair, it's because the tag pair is wrong. How is your current markup rendering as source?
    – 88mpg
    Feb 18, 2014 at 19:16
  • 1
    88mpg is correct. Remove that {if related_articles} check. The {related_articles} already acts as an if-check. If there are articles, it'll show them. if there aren't any articles, it won't show anything between the open and close.
    – SamC
    Feb 19, 2014 at 20:53

2 Answers 2

1

From the point that you probably always have related articles, you might try this:

Related Articles:    
<ul>
{related_articles}  
  <li><a href="{site_url}/news/industry/{last_segment}">{related_articles:title}</a></li>
{/related_articles} 
<ul>
1
  • I think that <li><a href="{related_articles:page_url}">{related_articles:title}</a></li> will work too.
    – SamC
    Feb 19, 2014 at 20:50
1

Here is the solution (hope this helps someone else):

                {related_articles}
                    {if related_articles:count == 1}
                    <h2 class="blue borderBottom">Related Articles:</h2>
                    <ul>
                    {/if}
                    <p><a href="{path="/spread-awareness/news/"}/{related_articles:url_title}">{related_articles:title}</a></p>
                    {if related_articles:count == related_articles:total_results}
                    </ul>
                    {/if}
                {/related_articles}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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