Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2014-10-22 14:02:34

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Article category list with images

I’m trying to build a list of article categories with images, limited to just 3 categories.
The list would be shown in the home page under a “Featured Topics” title, so ideally I want to show only the 3 categories with the most articles.
The snippet suggested by Els is perfectly working, but displays ALL categories.
Unfortunately there is no limit=“3” attribute to txp:category_list…

Is there another way to get only 3 “hot topics”?

Last edited by giampablo (2014-10-22 14:03:32)

Offline

#14 2014-10-23 12:46:10

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

Re: Article category list with images

giampablo wrote #285053:

Unfortunately there is no limit=“3” attribute to txp:category_list…

The problem is not only limit, but also sort, since you want to output the “most popular” categories, right? You could extract them from category_list with etc_query (plus XSL transform), but, from the beginning, it could be more efficient to go with a direct sql query:

<txp:smd_query query="SELECT Category1 FROM `textpattern` WHERE Category1 > '' GROUP BY Category1 ORDER BY COUNT(*) DESC LIMIT 3" break=",">
{Category1}
</txp:smd_query>

You will obtain a comma-separated list of “most popular” categories, that you can plug into <txp:category_list /> and then use Els snippet. Note that the code above includes the hidden/expired/future articles, you may need to add Status = 4 and so on to the WHERE clause of the query.

Offline

#15 2014-10-23 16:24:56

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Article category list with images

etc wrote #285079:

The problem is not only limit, but also sort, since you want to output the “most popular” categories, right?

Exactly. But now I am a little confused.
As far as I understand I should go first with a direct sql query, with smd_query, obtaining a “most popular” category list, then extract from this list the first 3 categories with etc_query, plug into <txp:categoy_list /> and last use Els snippet. Am I right?
Or can I go directly with above mentioned smd_query?

And can you tell me how to “plug into <txp:category_list />”?

Thanks

Offline

#16 2014-10-23 16:58:35

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

Re: Article category list with images

You should go first with a direct sql query, with smd_query, obtaining a three “most popular” category list, then extract from this list the first 3 categories with etc_query, that you plug into <txp:categoy_list /> and last use Els snippet.

giampablo wrote #285092:

And can you tell me how to “plug into <txp:category_list />”?

<txp:category_list
	categories='<txp:smd_query query="SELECT Category1 FROM `textpattern` WHERE Category1 > '''' GROUP BY Category1 ORDER BY COUNT(*) DESC LIMIT 3" break=",">{Category1}</txp:smd_query>'
>
...
</txp:category_list>

Offline

#17 2014-10-23 17:27:10

giampablo
Member
From: Italy
Registered: 2008-07-17
Posts: 86
Website

Re: Article category list with images

etc wrote #285093:

You should go first with a direct sql query, with smd_query, obtaining a three “most popular” category list, then extract from this list the first 3 categories with etc_query, that you plug into <txp:categoy_list /> and last use Els snippet.

<txp:category_list...

Great. Now I’m going to download the plug-in and give it a try.

To me queries are an unknown territory. I will study to find a way to extract from Category1 AND Category2.
In any case a category-list from cat1 only is good enough to get the 3 “most popular” categories.

Thanks again, etc

Offline

Board footer

Powered by FluxBB