Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-09-22 13:45:52

convoy
Member
From: Italy
Registered: 2010-02-08
Posts: 10

Display articles from multiple related category

Sorry for the beginner question, but…
I have for example a category “Brands” with multiple subcategories “Yamaha, Fender, …” and a category “Guitar” with subcategories “Electric, Classic, Acoustic”.

Now I have to show all the products of a brand, say Yamaha, and then I need to let restrict the article list only to “Acoustic”… So I want to be desplayed only the Acoustic Yamaha’s guitars.

I think I need some kind of specification like “?c=yamaha&c=acoustic” in a strict way, how can I do this?

Thanks

Offline

#2 2011-09-22 15:04:05

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display articles from multiple related category

That’s not a beginner question, it’s not so easily achieved, and not out of the box.

Here are two approaches: a patch (and the fact that it needed a patch tells something about the complexity) and a somehow related topic: Show articles from category and augment with articles from section.

I’d go with the latter, no update hassles and you learn something. Read the first two posts to get an idea of what is the problem and how it is approached. I think in post#2 it becomes clear what you can borrow from the line of action. The final code is in the last post.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2011-09-22 15:22:22

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display articles from multiple related category

Oh, and there’s of course smd_query. (Sorry, now really in a hurry.)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2011-09-22 15:44:17

convoy
Member
From: Italy
Registered: 2010-02-08
Posts: 10

Re: Display articles from multiple related category

Thank you, smd_query looks very interesting.

I didn’t think it was that hard and I hope it will be considered as a new feature, many applications (like my easy e-commerce showcase) need to be able to “run through” categories to reach the right article.
The limitation of two categories per article can be rounded in many cases but a better management of categories relations would be useful.

Anyway, I’ll study a solution and I’ll post here (if I’ll find any…)

Offline

#5 2011-09-22 15:50:37

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,549
Website GitHub Twitter

Re: Display articles from multiple related category

Hi

If there is a complexe relationship between article you can try to use smd_tag

Cheers

Offline

#6 2011-09-29 12:36:44

convoy
Member
From: Italy
Registered: 2010-02-08
Posts: 10

Re: Display articles from multiple related category

I tried both smd_tag and smd_query.

smd_query is pretty as powerful as easy to use, to (self)answer my post #1 I can do:

<txp:smd_query column="*"
     table="textpattern"
     where="Category1='yamaha' AND Category2='acoustic'"
     form="adv-search" wraptag="ul" break="li" />

Great.. but… Now the problem is how to make it dynamic and browsable.

After a few attempts I decided to leave the standard browsing as it is and build a advanced-search page to let the products be filtered for a non-blog site as mine.
I will put a code like the one above in a cross section called like “advanced-search” with an html-form containing checkboxes and controls for all my hierarchic categories, and, why not, some custom_field options…
Then I think I could set the right query according the submitted request…

Could it be a good solution in your opinion?

Thank you all.

Offline

#7 2011-09-30 00:17:38

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display articles from multiple related category

Mabe you could be interested in this topic’s links and outcome.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2011-09-30 12:17:00

convoy
Member
From: Italy
Registered: 2010-02-08
Posts: 10

Re: Display articles from multiple related category

Thanks, I’m actually using smd_if to parse some results, like:

<txp:smd_if field="{custom_1}" operator="not" value="">
€ {custom_1}
<txp:else />
Contact us
</txp:smd_if>

Works like a charm.

Offline

#9 2011-09-30 13:21:18

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display articles from multiple related category

There’s not even a plugin required if you just exchange the logic:

<txp:if_custom_field name="your-field-name" value="">
   Contact us
<txp:else />
   € <txp:custom_field name="your-field-name" />
</txp:if_custom_field>

In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2011-09-30 13:32:05

convoy
Member
From: Italy
Registered: 2010-02-08
Posts: 10

Re: Display articles from multiple related category

That’s not a matter of logic actually, txp:if_custom_field can only be used in an article context and it raises an error if used to parse a query result like:

<txp:smd_query column="*"
	table="textpattern"
	where="  Category1='<txp:variable name="brand" />'  AND Category2='<txp:variable name="cat" />' " limit="10"  form="advanced-search" wraptag="" break=" "  />

…isn’t it?

Offline

#11 2011-09-30 14:33:27

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,315

Re: Display articles from multiple related category

I only said my code will do the same as yours, but without using a plugin. Nothing more and nothing less.
By “exchange logic” I meant nothing more complicated than exchanging the top part of the IF switch with its bottom couterpart.
smd_if will also need article context, btw, if I’m not completely mistaken.

Re smd_query: wouldn’t it need a “query” parameter? But I’ve not learned its syntax by heart. Stef/Bloke, the plugin’s dev, is a über-nice guy who’d certainly assist you in the plugin’s thread.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#12 2011-09-30 14:53:16

convoy
Member
From: Italy
Registered: 2010-02-08
Posts: 10

Re: Display articles from multiple related category

Re:1 Misunderstanding…
Re:1.1 No, smd_if doesn’t need article context, that’s why I find it useful to parse any smd_query results.

Re:2 The query parameter is optional for non-SELECT or complex query. Standard SELECT doesn’t require that. I copy-pasted a working code.

Offline

Board footer

Powered by FluxBB