0

Does anybody have a way of using the channel:month_links tag (to create a list of links to monthly archive pages) that takes it's date point from a custom date field rather than the entry_date field? I have a channel where the user can enter details of journalistic articles that they have written; one of the channel fields is {publication_date}. I want my month_links to be in the vein of:

Articles published in...

  • June 2013
  • July 2013
  • August 2013
  • etc

so I need the tag to hook into the publication_date not the entry_date. So far I can't find a way.

I realise that I could insist that users use the entry date field as the publication date, but the downside of that is that I can't change the field name (and 'entry date' is not a good label for the field, it's misleading), nor can I add field instructions.

Any ideas?

2
  • 1
    One possibility might be to use an “event” plugin such as Low Events or EEvent Helper, peruse the ‘events’ tag at devot:ee for enlightenment…
    – 3Easy
    Oct 14, 2013 at 9:59
  • Thanks 3Easy. Yes, I guess that would be a way to do it. Indeed, I'm already using Low Events on a different part of the site, so it's already in the mix and ready to roll. I just wondered if there was a way of doing, natively, what seems like it should be easy. I guess I just have to accept that it needs third-party help and go the Add-On route after all. (And plop a feature request over to EllisLabs).
    – RickL
    Oct 14, 2013 at 15:13

1 Answer 1

2

If you can overcome your objections to using the native Entry Date I'd definitely opt for using that... However, if you want to essentially rebuild the month_links functionality yourself, you could do this with Stash (yet again!).

Try something like this, using two nested get_list tags: (if you're using an embedded view template you won't need the stash:parse tags, but they're handy here when setting and getting in the same template...)

{exp:channel:entries channel="articles" dynamic="no"}

    {exp:stash:append_list name="months-to-output" trim="yes"}
        {stash:month-num}{publication_date format='%m'}{/stash:month-num}
        {stash:month-title}{publication_date format='%F %Y'}{/stash:month-title}
    {/exp:stash:append_list}

    {exp:stash:append_list name="articles-by-month" context="{custom_date format='%m'}"}
        {stash:the-title}{title}{/stash:the-title}
        {stash:the-link}{url_title_path=articles}{/stash:the-link}
    {/exp:stash:append_list}

{/exp:channel:entries}

{!-- ==============================
TEST OUTPUT 
=================================== --} 

{exp:stash:parse process="end"}
    <ul>
    {exp:stash:get_list name="months-to-output"}
        <li>
            <h2>{month-title}</h2>
            <ul>
            {exp:stash:get_list:2 name="articles-by-month" context="{month-num}"}
                <li><a href="{the-link}">{the-title}</a></li>
            {/exp:stash:get_list:2}
            </ul>
        </li>
    {/exp:stash:get_list}
    </ul>
{/exp:stash:parse}
2
  • James, I think that since I've already got Low Events in place on the site and since I can co-opt it into this particular task, I'll go that route this time. But your Stash solution (oh, Stash, is there anything you can't do?) is very interesting -- even if it does make my head hurt -- and I'll keep it in a drawer for a time when I'm not using Low Events (and don't want to spend the cash on it just to get the Archive links I want). Cheers.
    – RickL
    Oct 14, 2013 at 22:38
  • BTW I take on board your recommendation to use the native entry_date field, but my objections still stand: the name (Entry Date) is a misnomer that is likely to mislead and confuse the site editor, and I can't mitigate that by adding field instructions. Also, I have several other channels that either use a native custom 'date' field or a Low Events field for date-related channel data, and thus the editor never actually has to bother explicitly setting the entry date. To require it in this one case would create some UX dissonance I think, so I wish to avoid it..
    – RickL
    Oct 14, 2013 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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