Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-07-11 21:19:07

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

How to get at the top the most updated category (of a category-list)?

In an old web site there are many articles listed in their respective categories; some old articles are listed at the top of the index page, although are also some categories, in the same page, in which are listed more recent articles.

So I wonder if there is any way to get the categories listed according to their listing most recent content inside; I mean: is there any <txp:category-list /> attribute allowing to get at the top of the page the most updated categories?

Offline

#2 2020-07-11 21:59:43

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: How to get at the top the most updated category (of a category-list)?

Nope, <txp:category_list /> is not linked to articles. Your best option would be a direct db query, either via <txp:php /> or some plugin (smd_query or etc_query). For example,

<txp:etc_query data="SELECT DISTINCT Category1 FROM textpattern WHERE Category1>'' ORDER BY MAX(Posted) DESC" break="," />

will give you a comma-separated list of distinct Category1 article fields sorted by the publish date. You can then pass this list to <txp:category_list /> via its categories attribute.

Offline

#3 2020-07-12 16:29:18

Bongo-man
Member
Registered: 2009-03-18
Posts: 243

Re: How to get at the top the most updated category (of a category-list)?

Thank you for your answer, but is a bit complicated.

Offline

#4 2020-07-12 16:57:34

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

Re: How to get at the top the most updated category (of a category-list)?

Bongo-man wrote #324450:

Thank you for your answer, but is a bit complicated.

Hi,

what you need to do is to install etc_query, paste the code provided and experiment in a sandspace. It may be simpler than it looks:)


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#5 2020-07-12 17:05:09

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: How to get at the top the most updated category (of a category-list)?

Bongo-man wrote #324450:

Thank you for your answer, but is a bit complicated.

Your request is a bit complicated :-) Actually, you should be able to do it in core:

<txp:variable name="recent_cats">
    <txp:article_custom category break="," limit="999">
        <txp:category1 />,<txp:category2 />
    </txp:article_custom>
</txp:variable>

<txp:category_list categories='<txp:variable name="recent_cats" />' />

Offline

#6 2020-07-13 13:07:05

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 975
Website

Re: How to get at the top the most updated category (of a category-list)?

etc wrote #324453:

Your request is a bit complicated :-)

Just a fwiw thought.

I get why it is a bit complicated given the article / category disconnect. I love that there is a work around – probably core work around, and how helpful you guys are.

Still, as a content management/publishing function it seems pretty simple/basic: Here’s a list of article in this category ordered by date published.

It’s too bad there isn’t a simple way for categories to access publish dates. (If only the world was perfect :-D)

Last edited by maverick (2020-07-13 23:16:25)

Offline

#7 2020-07-13 14:51:04

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: How to get at the top the most updated category (of a category-list)?

maverick wrote #324481:

Still, as a content management/publishing function it seems pretty simple/basic: Here’s a list of article in this category ordered by date published.

It’s too bad there isn’t simple for categories to access publish dates. (If only the world was perfect :-D)

Probably, but then you might also want a list of most active authors/keywords/sections/etc. I like the ‘building blocks’ nature of txp, and the code above is not that complicated. Put it in a short-tag and you’ll get a new tag, with extra yield parameters if needed.

Offline

#8 2020-07-14 09:08:12

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: How to get at the top the most updated category (of a category-list)?

An example (4.8.2+), fwiw:

Create an activecats misc-type form:

<txp:variable name="activecats">
    <txp:article_custom category yield="sort" break="," limit="999">
        <txp:category1 />,<txp:category2 />
        <txp:if_article_category number="1">
            <txp:variable name='<txp:category1 />-articles' add='<txp:yield />' />
        </txp:if_article_category>
        <txp:if_article_category number="2">
            <txp:variable name='<txp:category2 />-articles' add='<txp:yield />' />
        </txp:if_article_category>
    </txp:article_custom>
</txp:variable>

<txp:category_list categories='<txp:variable name="activecats" />' wraptag="ul" break trim>
    <txp:category link title section="" />
    <txp:variable name='<txp:category />-articles' wraptag="ol" />
</txp:category_list>

Pass it sort attribute and article tags, e.g.

<txp::activecats sort="Posted ASC">
    <li><txp:title /> (<txp:posted format="%F" />)</li>
</txp::activecats>

Offline

#9 2020-07-14 09:14:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,792
Website

Re: How to get at the top the most updated category (of a category-list)?

etc wrote #324501:

Create an activecats misc-type form… snip>

Holy batballs, that’s clever!


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#10 2020-07-14 09:25:33

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: How to get at the top the most updated category (of a category-list)?

Bloke wrote #324502:

Holy batballs, that’s clever!

Way funnier than a dedicated tag!

Offline

Board footer

Powered by FluxBB