Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-10-18 18:54:29

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 21

Article List Help

Please bear with me, as I know this is a total n00b question. I’ve spent a few days pouring over documentation, and I’m missing something obvious.

I’m creating a roster page for a fantasy wrestling/efed game. Eventually, this page will have four sections: Men Wrestlers, Women Wrestlers, Men Tag-Teams, Women Tag-teams. Each wrestler is an article, and each of these four divisions is a category. The page will have the four divisions and each division will list the articles for that category, with a link to the article.

I’m starting with a simple list of the “men_wrestlers” category, not worrying about links yet. I Here’s what I have currently (I’ve tried many different variations).

I have a form named list_male_wrestlers with this code:

<html>
<body>
<txp:if_article_list>
<txp:article category=“men_wrestlers”>
<txp:title /><br></txp:article>
</txp:if_article_list>

</body></html>

Then, I have a page named “roster,” with this:

<html>
<body>
<center><h2>Roster</h2></center><br><br>
<txp:output_form form=“list_male_wrestlers” />
</body>
</html>

Finally, I created a section called “roster” that includes the “roster” page. When viewing the section, all my HTML (which isn’t much) is displayed, but there is no article listing. Like I said, it’s something simple. What am I doing wrong?

Offline

#2 2022-10-18 19:10:04

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

Re: Article List Help

I think you should use <txp:article_custom /> here, since <txp:article /> does not accept category attribute, retrieving it from the context (mainly URL). The roster section articles should be displayed, though.

Offline

#3 2022-10-18 19:34:03

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 21

Re: Article List Help

That was it. Thank you!

Offline

#4 2022-10-18 22:35:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Article List Help

It may be helpful to understand the main difference between txp:article and txp:article_custom:

txp:article is context-sensitive, i.e. it responds to whatever is in the browser URL – if you’re viewing a section page, it shows articles in that section; if you’re on a category page, it shows articles in that category; if you’re viewing a category in a section page, it will filter by section and category; if you’re viewing an individual article, it shows you just that article.

Because txp:article is sensitive to context, it has fewer attributes for filtering content. By the same token, you don’t need to wrap it in if_article_list because it will detect that on its own. In an article list context, it will display relevant articles using the form you specify using listform and on an individual article page using the form you specify using the form attribute.

txp:article_custom is specific, i.e. it ignores the context and outputs what you tell it to using attributes like section="…" and category="". If you only want it to output content in certain situations, you need to wrap it in if_article_list, if_section name="…", if_category (etc.) tags. It’s great for things like “top article” lists in a sidebar, or a notice that should appear up front on section or individual article.

——

Armed with that knowledge, you can simplify your setup as follows:

Your wrestler page template:

<html>
<body>
<txp:if_article_list>
<h2 class="section-title">Wrestlers</h2>
</txp:if_article_list>
<txp:article form="wrestler_full_profile" listform="wrestler_preview" limit="999" />
</body>
</html>

and then two forms of type article:

wrestler_full_profile

<article class="wrester-profile">
    <txp:article_image />
    <txp:title wraptag="h1" />
    <txp:body />
</article>

and wrestler_preview:

<article class="wrestler-preview">
    <txp:article_image thumbnail />
    <txp:permlink><txp:title wraptag="h3" /></txp:permlink>
    <txp:excerpt />
</article>

That saves you having to make a full page template for every list of male and female wrestlers and tag teams. You just assign your articles to the respective categories or sections, and they’ll be filtered by what you put in the browser url, e.g.

www.domain.com/wrestlers/ —> all wrestlers
www.domain.com/wrestlers/?c=men-wrestlers —> men wrestlers
www.domain.com/wrestlers/?c=women-wrestlers —> women wrestlers
www.domain.com/wrestlers/?c=men-tag-teams —> male teams
www.domain.com/wrestlers/?c=women-tag-teams —> female teams
www.domain.com/wrestlers/name-of-wrestler —> profile of the wrestler


TXP Builders – finely-crafted code, design and txp

Offline

#5 2022-10-19 09:22:59

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Article List Help

Ha, it helps if I read your post properly. My apologies.

ironmangary wrote #333980:

I’m creating a roster page for a fantasy wrestling/efed game. Eventually, this page will have four sections: Men Wrestlers, Women Wrestlers, Men Tag-Teams, Women Tag-teams. Each wrestler is an article, and each of these four divisions is a category. The page will have the four divisions and each division will list the articles for that category, with a link to the article.

If you want to show four lists of different groups of articles on one page, then you do need txp:article_custom.

There are different ways you could achieve this, but a simple way would be to combine txp:category_list to iterate over your categories and txp:article_custom to output X articles in the respective category.

Let’s say, you keep the structure and page template from the previous post, i.e. each wrestler / tag-team is an article in the wrestlers section, assigned to the respective category. You can keep the page template above. For the roster section (or the default section if it’s your homepage), you’d create a new page template along these lines:

<html>
<head></head>
<body>
<h1 class="section-title">Roster</h1>
<txp:category_list categories="men-wrestlers, women-wrestlers, men-tag-teams, women-tag-teams" break="">
    <div class="roster-group">
        <txp:category title wraptag="h2" class="category-title" />
        <txp:article_custom section="wrestlers" category='<txp:category />' limit="10" form="wrestler_preview" />
        <p class="more-link">More <txp:category section="wrestlers" title link /></p>
    </div>
</txp:category_list>
</body>
</html>

That should output – for each of the category names specified (change to match your own) – a heading, a list of the ten most recent wrestler previews, and a link to the respective page with the full list of that wrestler category.

Note the single quotes in category='<txp:category />'. That means process the tag within the tag attribute and put its output here. As this is within a category_list, it will do that for each category in turn.

—-

If the more link doesn’t work as expected (I’ve forgotten whether the section attribute produces the desired link destination or something else), try:

<a class="more-link" href="/wrestlers/?c=<txp:category />">More <txp:category title /> →</a>

TXP Builders – finely-crafted code, design and txp

Offline

#6 2022-10-19 16:31:15

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 21

Re: Article List Help

Thanks Jakob! Lots of great tips for this beginner! :)

Offline

Board footer

Powered by FluxBB