News Module or Custom Directory Displaying By Month

Jun 16, 2011 10:18 pm

Trying to figure out how to display News articles by the month/year (similar to the Blog archive)....so having a link for all articles in June 2011, May 2011, etc. Also trying it with a Custom Directory, but not having much luck there either.

Thanks...Guy

Custom directory seems to work

Jul 14, 2011 5:30 pm

I think I have a way to do this using a custom directory.

First, you have to have create a directory that contains a separate field for month, day, and year in numerical format. (I'm opening a support ticket to add this functionality with a single field that uses a date format.) My fields are as follows:

name = name
misc1 = month (ex. 07)
misc2 = day (ex. 05)
misc3 = year (ex. 2011)

Next, you need to create two layouts. One for the list of items, and one for the list of date links. Both layouts should be sorted by the following values in the Sort fields, which sorts by year in descending order, month in descending order, and day in descending order.

misc3 DESC, misc1 DESC, misc2 DESC

For the list of items layout, set this up as a normal lister layout. I embedded my list layout in it just to keep things easy.

For the list of date links, here is my code. Be sure that you display All Items for the Number of items.

Body:

<h2>Date Links</h2>
[[repeat]]

Repeat:

[[item]]

Item:

<if ([[misc3]] != [[last_misc3]])>
    <div><a href="index.php?src=directory&view=datesort&query=misc3.eq.[[misc3]]">[[misc3]]</a></div>
    <div style="padding-left: 30px;"><a href="index.php?src=directory&view=datesort&query=misc3.eq.[[misc3]].and.misc1.eq.[[misc1]]">[[misc1]]</a></div>
<else>
    <if ([[misc1]] != [[last_misc1]])><div style="padding-left: 30px;"><a href="index.php?src=directory&view=datesort&query=misc3.eq.[[misc3]].and.misc1.eq.[[misc1]]">[[misc1]]</a></div></if>
</if>

The first conditional statement checks to see if the previous year is different from the current item year. If it is a different year, the system displays the item's year with a link to all items with that year set. It also displays the item's month, with a link to all items with that month AND year set.

If it is the same year, the else condition is used and it uses a second conditional to see if the previous month is different from the current item month. If it is a different month, the system displays the item's month with a link to all items with that month AND year. If it is the same month, nothing is displayed and it goes on to the next item.

The links used for the date links use query code with the misc fields to create a dynamic filtered list of items that match the criteria.

Hopefully, this will help you, but let me know if you have questions.