Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-03-09 22:30:33

surfwax95
Member
Registered: 2008-04-04
Posts: 38
Website

How do Categories work?

I’m sorry that the title is so vague, but really I’m lost from square one.

I’ve created a blog with limited functionality (archiving, RSS, article lists, etc), but Categories are proving quite difficult.

So far I’ve managed to list them out in my sidebar (all articles have been tagged with their respective categories) and I can output the appropriate categories when viewing a single article, my troubles begin when you actually click one of these Categories.

I’m brought to my Default page, the URL is site.com/category/specific_category/

I’ve tried simply making a section called “Categories” with appropriate article tags, but I can’t figure out how, when the user clicks a category, to send them to this new section. Ideally, when someone clicks a Category they’ll be taken to a page that lists all articles tagged with that Category…

So, please, someone help me wrap my mind around using Categories!

Thanks!

Last edited by surfwax95 (2010-03-09 22:31:19)


Caps lock is cruise control for cool. —Unknown

Offline

#2 2010-03-09 22:56:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: How do Categories work?

surfwax95 wrote:

when you actually click one of these Categories. I’m brought to my Default page

Hi surfwax95, that’s actually intended behaviour. Category list pages are processed by your default Page template. So, somewhere in your default Page — preferably before you output any <txp:article /> tags — you should put a conditional tag like this to test if the user has clicked on a category:

<txp:if_category>
	<h2><txp:category title="1" /></h2>

	<!-- Show 5 articles from the selected category and
		mark each one up with the category_list Form -->
	<txp:article form="category_list" limit="5" />

<txp:else />

	<!-- Not in a category list, so do something else, e.g. check if a search
		was initiated, or whether the user is on a section landing page or
		viewing an individual article, etc -->

</txp:if_category>

Does that help get you heading in the right direction?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2010-03-09 23:02:12

surfwax95
Member
Registered: 2008-04-04
Posts: 38
Website

Re: How do Categories work?

Absolutely!

I did not realize that was the behaviour of the if_category tag. It all makes sense now! :)

You’ve definitely pointed me in the right direction. I appreciate it!


Caps lock is cruise control for cool. —Unknown

Offline

#4 2010-03-09 23:53:20

surfwax95
Member
Registered: 2008-04-04
Posts: 38
Website

Re: How do Categories work?

Hm…strange…

I’m probably screwing something up here, but for some reason it’s not pulling the articles that are categorized. However, if I change <txp:article> to <txp:article_custom section=“blog”> it works beautifully, but then I get an error that says there’s not an article tag in the page “default.”

Any ideas?


Caps lock is cruise control for cool. —Unknown

Offline

#5 2010-03-10 00:11:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,942
Website GitHub

Re: How do Categories work?

surfwax95 wrote:

Hm…strange…

Odd indeed. It should work… Let’s see…

if I change <txp:article> to <txp:article_custom section=“blog”> it works beautifully

The article and article_custom tags are very different animals and not generally interchangeable. article_custom is not context-sensitive so it’ll dutifully pull out all articles in the given section, irrespective of what’s going on in the URL or elsewhere about your site.

The <txp:article /> tag is context sensitive and should therefore understand that if you are viewing a site.com/category/specific-category page and you’re inside a <txp:if_category> conditional, it is to only display articles from the given category in the URL.

A few things can foul this up though. On a techie level, one of them is clean URLs — but I assume that your Admin->Diagnostics tab checks out and doesn’t give any warnings.

If you used my code example verbatim, does the correct category title appear on your page inside the <h2> tags? If so, that’s a good start because the conditional is firing correctly! After that, what is the contents of your category_list form? You’ll need to have it render some article tags like <txp:title /> at a minimum to be able to see your articles. Perhaps it’s trying to render it and can’t find the Form for some reason (which may explain why the article_custom tag — without a form, i.e. using the default form — works).

In these circumstances the tag trace usually helps to shed some light on what’s going on.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2010-03-10 01:43:27

surfwax95
Member
Registered: 2008-04-04
Posts: 38
Website

Re: How do Categories work?

Well, looky there, I do indeed have some errors in my diagnostics, don’t know if these would cause the problems, but…:

File directory path is not writable: /home/.mamma/user/domain/new_site/files
bc. Temporary directory path is not writable: /home/.mamma/user/domain/new_site/textpattern/tmp ?
Old placeholder file is in the way: /home/.mamma/user/domain/rfp ?

User names and roots replaced…

I had installed TxP in a folder called “new_site,” but moved it into the “domain” folder to launch. I looked in my config file and changed the root URL and everything seems to be working fine, except this category thing and the diagnostics are obviously throwing errors. No idea!

Last edited by surfwax95 (2010-03-10 01:44:02)


Caps lock is cruise control for cool. —Unknown

Offline

Board footer

Powered by FluxBB