Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-01-02 03:26:05

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 25

Event listing split by years

I’m converting an existing site with a history of events going back around 5 years. Maximum number of events per year seems to be around 20. On the old site, they are grouped under multiple headings: “Upcoming events”, “Recent events”, “Gallery”, “2019 highlights”, “2017 highlights”, with no particular logic as to why one heading is used rather than another.

I have started loading all events under a single Section: “Events” with the event date used as the article published date. It’s all working, with future events highlighted on both the Events page and Front page. The list of events is split by year using a breakform.

But it’s getting unwieldy. I’d like to add navigation links by year at the top of the events page. I’m already using adi_menu so one solution would be to create new sections, one for each year, then use adi_menu to make them sub-sections under “Events”. But that means creating a new section each year in the future. I know it’s a small job but it’s not something the site author should have to do once I hand the site over.

Any suggestions?

And happy New Year to everyone. A vaccine and change of US president offers us some hope, at least. Sorry, UK, 2021 isn’t looking hopeful for you.

Cheers
Bruce

Offline

#2 2021-01-02 06:40:55

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,451
Website

Re: Event listing split by years

We can now have a section/category/title URL pattern. Would Events/YEAR/event-title work for you? The beauty of the new pattern is that you can also have urls such as section/category1/category2/title.

So, a method would be to create a category which you can name Years and subcategories with the actual years, such as 2015, 2016, etc. Check the code for our Projects section which starts on this line, for article lists.

Regarding the years sub-menu, you can use something like the following code in your events section

<txp:category_list parent="year" exclude="year" break="li" wraptag="ul">
<txp:category title="1" link="1" section="events" />
</txp:category_list>

Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.

Offline

#3 2021-01-02 08:39:24

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 25

Re: Event listing split by years

Thanks, Yiannis,
That should work for me. With bonus code examples too!

Thanks again. Have a great 2021

Cheers
Bruce

Offline

#4 2021-01-02 22:35:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,026
Website

Re: Event listing split by years

One other idea: I guess you’re already using txp:if_different in combination with txp_posted and just the year as format to insert year headings via your breakform into your list of articles sorted by posted date.

If you also give each heading an id attribute, e.g. id="<txp:posted format="%Y" />", then you could build a nav element elsewhere on your page using txp:article_custom and if_different for just the year and the href="#<txp:posted format="%Y" />" to produce the jump links to the relevant heading.

Alternatively you could build a summary / details markup with your breakform.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2021-01-03 12:29:39

etc
Developer
Registered: 2010-11-11
Posts: 4,051
Website

Re: Event listing split by years

In 4.8.5 section/year/ URLs are recognized in year_month_day_title mode, so you will be able to create a navigation bar with something like

<txp:article_custom section="events" fields="year(posted)" limit="99" wraptag="ul" break>
    <a href="<txp:section name='events' url /><txp:posted format="%Y" />/">
        <txp:posted format="%Y" /> (<txp:yield item="count" />)
    </a>
</txp:article_custom>

Online

#6 2021-01-03 23:45:13

Bruce Bowden
Member
From: Melbourne, Australia
Registered: 2020-10-22
Posts: 25

Re: Event listing split by years

Hi Oleg,
That idea works perfectly with just a couple of small tweaks. Just one question: You have included a fields tag in your code. There is no documentation (yet) for the fields tag and your code seems to work without it. Can you point to some more details on its usage.
My adjusted code is:

<txp:article_custom section="events" fields="year(posted)" limit="99" wraptag="ul" break="" sort="Posted desc" >
<txp:if_different test='<txp:posted format="%Y" />' >
    <li><a href="<txp:section name='events' url /><txp:posted format="%Y" />/">
        <txp:posted format="%Y" /> 
    </a></li>
</txp:if_different>
</txp:article_custom>

Stay safe
Bruce

Offline

#7 2021-01-04 09:39:30

etc
Developer
Registered: 2010-11-11
Posts: 4,051
Website

Re: Event listing split by years

Hi Bruce,

fields attribute idea is outlined here. It avoids simple if_different constructions when you need to aggregate partial article data (say, output all authors having published in the current section). In 4.8.5 we have added few date functions (year, month, etc) as possible aggregators, so you can easily construct yearly (monthly, etc) archives navigation.

If you are on 4.8.4, fields="year(posted)" has no effect and can be removed or replaced with fields="section, posted".

Online

Board footer

Powered by FluxBB