0

I am not sure if anyone can help me!

I'm using the following code to display a list of articles and it works, however there are two issues.

The first is the date of each article is the same for each list item, when it should be different.

The second issue is that if the relationships field is empty, I want to NOT display any code, including the H4 tag.

So if there are NO related papers, nothing in the HTMl will show.

I have tried a number of things, maybe I need to use entry id?

Best wishes.

Graham

<!-- Related Papers -->
<div class="row">
<div class="large-12 columns">
<h4>Related Papers</h4><hr>
{exp:channel:entries channel="policy_papers" status="open" limit="10"}
{pp_related_papers}
{if pp_related_papers:count == "1"}
<ul>
{/if}
<li><a href="{path="policy-papers/papers"}/{pp_related_papers:url_title}"><h5>{pp_related_papers:title}</h5></a>
<h6 class="entry-meta">by {pp_related_papers:pp_author_one} {if pp_related_papers:pp_author_two != ""}and {pp_related_papers:pp_author_two}{/if} | <time datetime="{entry_date format="%Y-%m-%dT%H:%i"}" pubdate>{date_heading}{entry_date format="%d %F %Y"}{/date_heading}</time></h6><hr></li>
</ul>
{if pp_related_papers:count == pp_related_papers:total_results}
</ul>
{/if}
{if pp_related_papers:no_results}No related entries{/if}
{/pp_related_papers}
{/exp:channel:entries}
</div>
</div>
<!-- End Related Papers -->
2
  • what date you want to show? Child (related) documents or parent document (as you have now)?
    – Max Lazar
    Feb 7 '14 at 10:42
  • Hi Max, I would like to show the parent entry date, which is the date the entry was published. Feb 7 '14 at 10:50
1

regarding second q, possible stash will help you

{exp:channel:entries channel="policy_papers" status="open" limit="10"}
 {pp_related_papers}
    {exp:stash:append name="related_papers"}
    {if pp_related_papers:count == "1"}
    <ul>
    {/if}
    <li><a href="{path="policy-papers/papers"}/{pp_related_papers:url_title}"><h5>{pp_related_papers:title}</h5></a>
    <h6 class="entry-meta">by {pp_related_papers:pp_author_one} {if pp_related_papers:pp_author_two != ""}and {pp_related_papers:pp_author_two}{/if} | <time datetime="{entry_date format="%Y-%m-%dT%H:%i"}" pubdate>{date_heading}{entry_date format="%d %F %Y"}{/date_heading}</time></h6><hr></li>
    </ul>
    {if pp_related_papers:count == pp_related_papers:total_results}
    </ul>
    {/if}
    {if pp_related_papers:no_results}No related entries{/if}
     {/exp:stash:append}
{/pp_related_papers}   
{/exp:channel:entries}    

{if {exp:stash:not_empty name="related_papers"}}
<!-- Related Papers -->
    <div class="row">
        <div class="large-12 columns">
        <h4>Related Papers</h4><hr>
            {exp:stash:get name="related_papers"}
        </div>
    </div>
<!-- End Related Papers -->
{/if}
3
  • Hi Max, Many thanks. I will give this a try and post back if it works. Best wishes Feb 7 '14 at 12:31
  • I didn't need to use stash, as this worked for the date: <time datetime="{pp_related_papers:entry_date format="%Y-%m-%dT%H:%i"}" pubdate>{date_heading}{pp_related_papers:entry_date format="%d %F %Y"}{/date_heading}</time> Feb 7 '14 at 14:19
  • my mistake - stash it is was answer for "NOT display any code". Regarding date - yes, it why asked you what date you really want to show.
    – Max Lazar
    Feb 7 '14 at 15:51

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.