2

I have a Newsroom page that combines "In the News" channel entries and "Press Release" channel entries and I need to sort by different dates. Press Releases use the entry_date because they go live on a specific date. In the News entries have their own pub_date date field since article publication dates might not necessarily align when the article is posted to the site (entry_date). While I could use entry_date for In the News entries, in the future an Events channel field will be added and included in this list. Events can't use the entry_date because they need to be listed on the site much earlier, however, the request is to have the date listed and sorted by be the event start date.

Is there a way to sort entries by multiple dates like this? I tried:

{exp:channel:entries channel="in_the_news|press_releases" orderby="pub_date|entry_date" sort="desc"}

but the entries listed all In the News article sorted by pub_date then all the Press Releases sorted by entry_date, not a mix of the two sorted by pub_date is ones existed then entry_date it not.

UPDATE:

Current code based on @stuartmcd69's answer below.

{exp:stash:set_list name="newsroom" parse_tags="yes"}
    {exp:channel_entries channel="in_the_news|press_releases" dynamic="no"}
        {!--  create stash variables --}
        {stash:news-article_title}{news-article_title}{/stash:entry_title}
        {stash:news-publication_name}{news-publication_name}{/stash:entry_title}
        {stash:pr-title}{pr-title}{/stash:entry_title}

        {!-- capture dates from both channels and convert to a universal date variable --}
        {stash:universal_date}
            {exp:switchee variable="{channel_short_name}" parse="inward"}
                {!-- News Article dates --}
                {case value="in_the_news"}
                    {news-publication_date}
                {/case}

                {!-- Press Release dates --}
                {case value="press_release"}
                    {entry_date}
                {/case}
            {/exp:switchee}
        {/stash:universal_date}
    {/exp:channel_entries}
{/exp:stash:set_list}

<dl id="news_list" class="dl-horizontal">
{exp:stash:get_list name="newsroom" orderby="universal_date" sort="desc"}

    {!-- Display entry based on channel name --}
    {switchee variable="{channel_short_name}" parse="inward"}

        {!-- News Articles --}
        {case value="in_the_news"}
            <div class="news_item in_the_news year-{year}">
                <dt>
                    <h4>{news-publication_date format="%F %j, %Y"}</h4>
                </dt>
                <dd>
                    <h4><a href="{news-link_to_article}" target="_blank">{news-article_title}</a></h4>
                    <p>{news-publication_name}, {news-publication_date format="%F %j, %Y"}</p>
                </dd>
                <hr />
            </div>
        {/case}

        {!-- Press Releases --}
        {case value="press_releases"}
            <div class="news_item press_releases year-{year}">
                <dt>
                    <h4>{entry_date format="%F %j, %Y"}</h4>
                </dt>
                <dd>
                    <h4><a href="{page_uri}">{pr-title}</a></h4>
                </dd>
                <hr />
            </div>
        {/case}
    {/switchee}
{/exp:stash:get_list}
</dl>
1

I'd use stash fo sure!

The following is a guide and not a verbatim copy/paste solution. Theory is capture a list of the items you want to capture & display AND also capture the relevant date to use to display relevance.

{exp:stash:set_list name="recent_news" parse_tags="yes"}
 {exp:channel_entries ...}
  {stash:entryid}{entry_id}{/stash:entryid} //Declare Entryid
  {stash:entry_title}{title}{/stash:entry_title} //Declare Title
  // Capture as much or as little as required. etc etc…
  {stash:alpha_date} //Capture relevant date for particular channel
    {exp:switchee variable="{channel_short_name}" parse="inward"}
      {case value="press_release"}
        {entry_date}
       {/case}
       {case value="in_the_news"}
         {pub_date}
       {/case}
    {/exp:switchee}
  {/stash:alpha_date}
{/exp:channel_entries}
{/exp:stash:set_list}

Then further down the template, spit it out by the captured "alpha_date":

{exp:stash:get_list name="recent_news" orderby="alpha_date" sort="desc"}
  {title}/{entryid}
{/exp:stash:get_list}
| improve this answer | |
  • Stuart (and no, I'm not referring to myself in the third person), I took a stab at your suggestion above and went through the Stash docs to see if I could not only copy/paste the code but figure out what's going on so I could modify this for my needs. I, however, am getting the following error: Error The following tag has a syntax error: {exp:stash:get_list} Please correct the syntax in your template. I'm assuming this might have something to do with my use of switch to output modified content based on the source channel but I'm not entirely sure and the error message isn't too helpful. – Stuart McCoy Oct 29 '13 at 16:56
  • OK, disregard that error, that was a PEBCAK error of the highest order. It typically helps if you install Stash BEFORE you try to use Stash tags. Let me look at the code again and see if I can get it to work. – Stuart McCoy Oct 29 '13 at 19:08
  • Lol, makes it hard to problem solve ;) Did the code you posted actually work? – stuartmcd69 Oct 29 '13 at 21:59
  • I have not had a chance to get back to it yet. The dates for the In the News can now use the entry_date but when I get to the Events channel in the near future I'll have to address this issue again. I think Stash will work though, I just need to get the correct variables setup first. – Stuart McCoy Oct 30 '13 at 20:08
0

Using two dates will rarely work because every datestamp will be different (down to the seconds value).

The solution may be only to use pub_date in the entries loop and sort by that. Then use the entry_date solely for specifying when the item is published. You would have to always have a pub_date for each entry.

| improve this answer | |

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.