Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2018-08-02 12:34:55

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

Re: troubles with txp:related_articles

As txp:related_articles makes use of txp:article_custom internally, maybe adding the attribute status="4" may help. I’m not sure but try that first.

Alternatively, try you could do it in two steps:

<txp:variable name="random_related_articles"><txp:related_articles limit="10" wraptag="" break="," sort="rand()" section='<txp:section />' ><txp:article_id /></txp:related_articles></txp:variable>
<txp:article_custom limit="4" status="live" id='<txp:variable name="random_related_articles" />' wraptag="ul" break="li">
<div class="related-image">
    <a href="<txp:permlink />" rel="bookmark" title="<txp:title />"><txp:article_image thumbnail="1" width="230" height="180" /></a>
       <div class="related-text">
           <a href="<txp:permlink />"><txp:title /></a>
       </div>
  </div>
  <div class="related-small">
      <a href="<txp:permlink />" class="related-headline"><txp:title /></a>
   </div>
</txp:article_custom>

Maybe something like that? If you have a lot of sticky articles, you might have to adjust the limit attribute in the first part to ensure you always have enough to get 4 live articles in the second part.


TXP Builders – finely-crafted code, design and txp

Offline

#14 2018-08-02 15:39:49

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

Re: troubles with txp:related_articles

It’s another silly bug of mine, sorry. Awaiting 4.7.2, you can do the following

<txp:related_articles limit="4" wraptag="ul" break="" sort="Status, rand()" section='<txp:section />'>
<txp:if_custom_field name="status" value="4">
<li>
  <div class="related-image">
    <a href="<txp:permlink />" rel="bookmark" title="<txp:title />"><txp:article_image thumbnail="1" width="230" height="180" /></a>
       <div class="related-text">
           <a href="<txp:permlink />"><txp:title /></a>
       </div>
  </div>
  <div class="related-small">
      <a href="<txp:permlink />" class="related-headline"><txp:title /></a>
   </div>
</li>
</txp:if_custom_field>
</txp:related_articles>

Offline

#15 2018-08-02 21:26:49

singaz
Member
Registered: 2017-03-12
Posts: 150

Re: troubles with txp:related_articles

jakob, thank you!

etc, thank you!

I decided my question.

I like textpattern. I like the community.

I’ve been trying to do this myself for a long time. And I got a quick response from the community.

Thank you.


Sorry my horror English. I’m learning textpattern, I’m learning English

Offline

Board footer

Powered by FluxBB