0

Does anybody know of a way to output a list of yearly archives using a custom date field? Low Yearly Archives is exactly the functionality I need, but referencing a custom date field, not the entry_date field.

Thanks! - B

2

It's not supported out of the box, but if you change the SQL query that the plugin uses, it should work with a custom date field (not taking DST into account, tho):

Look up this in pi.low_yearly_archives.php:

$sql = "SELECT
        CONCAT(t.year,t.month) AS ym,
        COUNT(*) AS num_entries
    FROM
        exp_channel_titles t
    INNER JOIN
        exp_channels w
    ON
        t.channel_id = w.channel_id
        {$sql_cat_join}
    WHERE
        w.site_id = '{$sql_site_id}'
        {$sql_category}
        {$sql_expired}
        {$sql_future}
        {$sql_status}
        {$sql_channel}
        {$sql_author}
    GROUP BY
        ym
    ORDER BY
        ym ASC
";

And change that to:

$sql = "SELECT
        FROM_UNIXTIME(d.field_id_XX, '%Y%m') AS ym,
        COUNT(*) AS num_entries
    FROM
        exp_channel_titles t
    INNER JOIN
        exp_channels w
    ON
        t.channel_id = w.channel_id
    INNER JOIN
        exp_channel_data d
    ON
        t.entry_id = d.entry_id
        {$sql_cat_join}
    WHERE
        w.site_id = '{$sql_site_id}'
        {$sql_category}
        {$sql_expired}
        {$sql_future}
        {$sql_status}
        {$sql_channel}
        {$sql_author}
    GROUP BY
        ym
    ORDER BY
        ym ASC
";

Where field_id_XX should be changed to whatever the actual field ID is.

| improve this answer | |
  • Low! Thank you for the detailed answer. This is fantastic. I actually use Low Yearly Archives already for other purposes that rely on the entry_date functionality. Any chance that a future version might have a parameter that selects a custom date field? – Brett Apr 24 '13 at 4:24
  • Sure, I'll consider it. – Low Apr 24 '13 at 10:29
  • Low, I just found this thread whilst hunting for an answer to the same question -- how to create yearly archives based on a custom date field rather than the entry date. I looked in the pi.low_yearly_archives.php file but couldn't see the code block you refer to in your answer (I did a quick 'Find' search for "$sql" and got no result). Has the code changed since your answer? Anyway, consider this a ‘+1’ request for the ability to hook into custom fields. Thanks. – RickL Oct 13 '13 at 21:35
  • Yeah, code's changed since then. This is the version of LYA the query refers to: github.com/low/low_yearly_archives/tree/v2.2 – Low Oct 14 '13 at 11:53
0

EDIT2: EEvent helper will match a custom date field to your entry's publication and expiration date if you can live with that.

EDIT1: sorry, misread your question. Thought you needed a custom year range

Combining Low Archives with the dt plugin should give you what you need.

| 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.