Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-05-06 20:45:47

coryldork
Member
From: Canada
Registered: 2010-09-03
Posts: 10

Display list of articles after clicking the category link

Alright, I’ve been using Textpattern for a while. I’m doing some restructuring at the moment, and I’ve gotten pretty confused. Maybe I’m burnt out.

When I click on the category for an article, it brings me to a “www.website.com/category/specified-category” URL, which is what I want. However, the page doesn’t have any of the page or form coding from Textpattern, and comes out blank. It displays some of my page code with my header and footer inclusions, but nothing else in the main content section.

I’m not sure where I’m supposed to put any code for the categories when I want a list of articles in that category to be displayed. Do I put it in a form? Do I put it in a page? And do I use if_category or if_article_category to achieve this list? Or would it be related_articles instead? I’ve been Googling around for hours today trying to figure it out, and while I understand the tags decently, I don’t know where to put the code.

Any help would be great.

Last edited by coryldork (2015-05-06 20:46:22)

Offline

#2 2015-05-06 21:52:33

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

Re: Display list of articles after clicking the category link

If you’re using the url scheme you describe (i.e. not categories within a section), the standard txp:article tag should automatically detect that it is a category list and filter your article listform by that category.

You only need if_category to output certain content that should only show on the category list view.

For example put this in your page template:

<h2>
  List of articles
  <txp:if_category>
    in the <txp:category title="1" /> category
  </txp:if_category>
</h2>
<txp:article listform="article-list-form" form="article-individual-view-form" />

which would show you a list of articles on the homepage, and filtered list of articles when your url has /category/category-name in it.

You’d use if_article_category if you’re detecting something on a per article basis in a normal article list, e.g. in your article-list-form, you might have:

<article>
<txp:permlink><txp:title /></txp:permlink>
<txp:if_article_category name="feature">
  <em>featured article</em>
</txp:if_article_category>
<txp:excerpt>
</article>

which would add a “featured product” flash on each article assigned to the feature category.

If on the other hand you are trying to handle categories within a specific section, e.g. www.site.com/products?c=featured txp:article won’t work here as it doesn’t automatically detect the context. Here you need to build your own output using a combination:

<txp:if_category>
  <txp:article_custom category='<txp.category />' …>
</txp:if_category>

which outputs a list of article filtered by the current category (tags in tags using single quotes).


TXP Builders – finely-crafted code, design and txp

Offline

#3 2015-05-07 12:48:16

coryldork
Member
From: Canada
Registered: 2010-09-03
Posts: 10

Re: Display list of articles after clicking the category link

The standard txp:article tag isn’t detecting and displaying a list, which is what I’m trying to do, across all sections.

I don’t know what to do with listform. I’ve been using if_article_list to manage article lists, so I don’t understand what listform is for. If I apply it to my standard txp:article, it lists the articles correctly based on the form, but not if a category is selected and the articles in that category are supposed to show up.

Edit: I’ve found out one of the issues I was having. I wasn’t editing the right page, but now that I’ve found which page is used for categories (default, obviously /facepalm), my txp:article isn’t working, regardless of which form or listform I use. I clear my cache after every edit, by the way, so that’s definitely not affecting anything.

Last edited by coryldork (2015-05-07 13:36:04)

Offline

#4 2015-05-07 13:38:15

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

Re: Display list of articles after clicking the category link

coryldork wrote #290547:

my txp:article isn’t working, regardless of which form or listform I use. […] one of the issues I was having.

Pardon, what’s your problem currently?

Last edited by uli (2015-05-07 13:42:35)


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

Offline

#5 2015-05-07 13:47:00

coryldork
Member
From: Canada
Registered: 2010-09-03
Posts: 10

Re: Display list of articles after clicking the category link

My problem is still displaying a list of articles when a category is selected.

However, in the page used to display those articles, I am unable to call up a form in order to display those articles. Basically, the regular txp:article does not work to display the articles in the category.

Last edited by coryldork (2015-05-07 13:48:33)

Offline

#6 2015-05-07 14:22:47

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

Re: Display list of articles after clicking the category link

It could be that the articles of the concerned category belong to some section that is not “on front page”.

Offline

#7 2015-05-07 14:23:22

coryldork
Member
From: Canada
Registered: 2010-09-03
Posts: 10

Re: Display list of articles after clicking the category link

If this helps at all, this is the structure for the page:

<txp:php> (php include for header) </txp:php>
<txp:if_category>
<h1>Category: <txp:category title="1" /></h1>
<txp:article form="article_listing" limit="8" />
Articles here
<h2 class="center"><a class="meta" href="<txp:older />">&laquo; Older Posts</a> // <a class="meta" href="<txp:newer />">Newer Posts &raquo;</a></h2>
<txp:else />
<txp:article form="static" limit="1" status="sticky" />
</txp:if_category>
<txp:php> (php include for footer) </txp:php>
<txp:article form="article_listing" limit="8" />

is the part that doesn’t show up when looking at the category link. This part doesn’t show up regardless of the form I use. It is the only part of the page that does not show up, and it is only happening with the /category/category-name aspect of the site—which is why my problem is still the failure to list articles in a category once the category is selected.

The else statement is used for the home page of my site, and I’m pretty sure it doesn’t affect the rest.

Offline

#8 2015-05-07 14:24:35

coryldork
Member
From: Canada
Registered: 2010-09-03
Posts: 10

Re: Display list of articles after clicking the category link

etc wrote #290550:

It could be that the articles of the concerned category belong to some section that is not “on front page”.

/facepalms forever

This was the problem. Thank you.

Last edited by coryldork (2015-05-07 14:25:20)

Offline

Board footer

Powered by FluxBB