Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-09-16 09:24:52

bashirnoori
Member
From: Afghanistan
Registered: 2012-10-02
Posts: 72

article_custom dynamic in different way

I want to list the articles title in the following format:


<li>
    the title of article 1
    the title of article 2
    the title of article 3
</li>
<li>
    the title of article 4
    the title of article 5
    the title of article 6
</li>
    ...

I’m trying in the following codes, but it’s not dynamic and professional way.


<li>
    <txp:article_custom limit="3">
        <txp:title />
    </txp:article_custom>
</li>
<li>
    <txp:article_custom offset="3" limit="3">
        <txp:title />
    </txp:article_custom>
</li>
...

Offline

#2 2017-09-16 09:43:49

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

Re: article_custom dynamic in different way

There are probably multiple ways of doing that, and if your intention is just for layout purposes, you might want to simply wrap every title in an <li>…</li> and use CSS nth-child / nth-of-type to achieve the desired layout. That’s also most flexible for responsive layouts, where you may want to break every second rather than every third title, etc.

However, to come back to your specific example, you could do that with a txp variable and adi_calc. Something like this:

<txp:variable name="group-counter" value="0" />

<ul>
  <li>
    <txp:article_custom section="your-section" limit="9999">
      <txp:adi_calc name="group-counter" add="1" />
      <txp:title />
      <txp:if_variable name="group-counter" value="3">
  </li>
  <li>
      <txp:variable name="group-counter" value="0" />
      </txp:if_variable> 
    </txp:article_custom>
  </li>
</ul>

That should advance a counter and on every third counter add your tags and reset the counter again.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2017-09-16 10:39:39

etc
Developer
Registered: 2010-11-11
Posts: 5,087
Website GitHub

Re: article_custom dynamic in different way

jakob wrote #307035:

There are probably multiple ways of doing that

Certainly. And if this demand is popular enough, we can add some breakby attribute to article/image/… lists.

Last edited by etc (2017-09-16 10:46:09)

Offline

Board footer

Powered by FluxBB