Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-08-23 12:07:01

Gallex
Member
Registered: 2006-10-08
Posts: 1,300

Create article list grouped by month

guys, i need your help to create article list grouped by month. i stuck myself…

display all articles in section ‘‘events 2023’‘ grouped by month. desired output should be:

JANUARY
article1, article2, article3…

FEBRUARY
article4, article5, article6…

MARCH
article7, article8, article9…

my current code:

<txp:if_individual_article>
<txp:article>
<div class="title">
<h1><txp:title /></h1>
<p class="posted"><txp:posted format="%d.%m.%Y" /></p>
</div>
<div class="body">
<txp:body />
</div>
</txp:article>

<txp:else />

<txp:category_list parent='<txp:section />' exclude='<txp:section />'>
<txp:if_different><txp:category title="1" wraptag="h4" /></txp:if_different>
<txp:article frontpage="0" limit="12" sort="Posted desc" wraptag="div" break="div" class="tulbad-4 tulbad-50 col-content-2">
<div class="article-img-2">
<txp:if_article_image>
<txp:permlink><txp:article_image /></txp:permlink>
<txp:else />
<txp:images id="8,5" limit="1" sort="rand()" />
</txp:if_article_image>
<div class="clock"><span class="posted">
<txp:if_custom_field name="kuupäev"><txp:custom_field name="kuupäev" /></txp:if_custom_field>
</span></div>
</div>
<h2><txp:permlink><txp:title /></txp:permlink></h2>
<txp:if_excerpt><txp:excerpt /></txp:if_excerpt>
</txp:article>
</txp:category_list>

</txp:if_individual_article>

and current output
duplicates all articles under all categories :(

Offline

#2 2023-08-23 12:22:18

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

Re: Create article list grouped by month

I’m not sure how your categories feature in this, but essentially an article list grouped by month is a regular chronological list of articles with month/year headings inserted at the right points. For that you can use:

<txp:if_different>
    <txp:posted format="%B %Y" wraptag="h3" />
</txp:if_different>

within your article_list form or code as shown in this txptip.

If you need to do more complex wrapping of the articles in each month group, see this thread for a similar discussion.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB