Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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
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
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
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
Re: How to get at the top the most updated category (of a category-list)?
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
Offline
Re: How to get at the top the most updated category (of a category-list)?
maverick wrote #324481:
It’s too bad there isn’t a simple way for categories to access publish dates. (If only the world was perfect :-D)
Not sure for the world, but txp (4.8.4) tends to perfection:
<!-- get a list of 'recent' categories -->
<txp:article_custom category fields="Category1, Category2" sort="MAX(Posted) DESC" break="," trim replace>
<txp:category1 />,<txp:category2 />
</txp:article_custom>
Offline