Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-08-24 21:21:15

code365
Member
From: California
Registered: 2009-08-16
Posts: 45

Categories Articles

Hopefully someone can help me.

I have two section A and B which, is using the same template. A and B section are using two different categories. In each categories have article for each section. For some reason each section categories are showing up on the each section. Can someone help me figure out what I am doing wrong.

<txp:category_list break="" type="article" categories="cat 1, cat 2">
    <txp:article_custom category='<txp:category />' break="" wraptag=""  limit="9">
        <a class="list-group-item list-group-item-action" href="<txp:permlink />"><txp:title /></a>
    </txp:article_custom>
</txp:category_list>

Offline

#2 2019-08-24 21:47:11

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,547
Website

Re: Categories Articles

Your code should produce a list of 9 linked article titles from cat 1 followed by a list of 9 linked article titles from cat 2. It would do that on whatever section your are looking at.

If your articles are also assigned to the section you want to display them on, you could add section='<txp:section />' to your article_custom tag in your code to restrict the output to those articles in the currently shown section.

If your articles are assigned to many different sections and you’re using the categories as a way of grouping them together to show on a single section page you may want to try something like this:

Variant A where the page’s section name matches the category name exactly:

<txp:article_custom category='<txp:section />' break="" wraptag="" limit="9">
    <a class="list-group-item list-group-item-action" href="<txp:permlink />"><txp:title /></a>
</txp:article_custom>

Variant B where the page’s section name does not match the category name. Here you can use variables as a bridge to map the page’s section name to the category name you want to use:

<txp:variable name="section-a_category" value="cat 1" />
<txp:variable name="section-b_category" value="cat 2" />
<txp:article_custom category='<txp:variable name=''<txp:section />_category'' />' break="" wraptag="" limit="9">
        <a class="list-group-item list-group-item-action" href="<txp:permlink />"><txp:title /></a>
    </txp:article_custom>

where section-a (change to your own section’s name) should show articles in category cat 1 and analogue for section-b. Note the singlequotes and then pairs of single quotes (to get output of a tag in a tag in tag). You shouldn’t need txp:category_list if you just want to show articles from a single category.

The above is untested. And if I’ve not understood your intentions properly, could you elaborate.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2019-09-01 01:13:23

code365
Member
From: California
Registered: 2009-08-16
Posts: 45

Re: Categories Articles

@ Jakob thank you much for your help. I need to understand txp variable tag but variant A work great.

Offline

#4 2019-09-01 09:30:28

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,547
Website

Re: Categories Articles

Glad you got it working. If Variant A already works, you don’t need Variant B.

I need to understand txp variable tag

The txp:variable tag just makes it possible to store some information for later use on the page. That makes it a very versatile tool. In the example in Variant B, the variables can be used map a category (or several categories) to a section. Here an example with several categories mapped to one section with a different name:

If you want to show articles categorised as fruit, vegetables and pulses in the section called produce, you would do:

<txp:variable name="produce_category" value="fruit,vegetables,pulses" />

And perhaps you want to show articles categorised as tools, containers and pots in the section called gardening. Then you’d do:

<txp:variable name="gardening_category" value="tools,containers,pots" />

With the code in Variant B above, when a visitor visits the section produce, it looks for the variable called produce_category and plugs its value (“fruit,vegetables,pulses”) into the article_custom tag as a filter by category, causing it to show all the articles categorised as fruit, vegetables and pulses. The same idea applies to when a visitor visits the section gardening.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB