Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-09-03 07:13:59

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Categories and clean URL

Hi!
It’s been like forever since the last time I posted here, sorry :/

My questions are:
1. Is there any new development regarding assign an article to more then only up to 2 categories?

2. Can we have a clean URL including category name please? I need section/category instead of section?c=category.
(without the broken old plugin name: gbp_permanent_links)

Offline

#2 2016-09-03 07:50:33

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

Re: Categories and clean URL

Regarding your first question:

1) I don’t think so, but there’s rss_unlimited_categories or smd_tags.

Regarding your second question:

You should be able to redirect with smd_redirect (see the date-based archive example for a relevant example) but as far as I recall the url also changes.

For the most part I do this with a line in .htaccess. That’s absolutely fine for most sites where the structure doesn’t vary much after the site has been done, but less ideal if you have a site that changes often.

Add something like this before textpattern’s rewrite rules, e.g.:

RewriteRule ^(section)/category/([^/]+)?/?$  index.php?s=$1&c=$2 [L]

You can use (section-one|section-two) if you want it to work in different sections.

And you can replace category with another word if you want. If you want to be able to use different words for category, e.g. for a multilingual site or because you want different words for different sections, you can still do it with one line:

RewriteRule ^(section)/(category|kategorie)/([^/]+)?/?$  index.php?s=$1&c=$3 [L]

Note the final $2 in the previous example has now become $3 because there are now three matching groups.

For all of the above, you need to create your category links manually with textpattern, e.g.:

<a href="/<txp:section />/category/<txp:category />"><txp:category_title /></a>

instead of using the in-built link="1" attribute.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2016-09-03 08:27:27

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Categories and clean URL

Thank you very much J ! :)

For my first question, I think I can do that by simply provide a checkbox list using glz_custom_fields plugin,
and then use my_custom_category_field="" in the article/article_custom tags, something like this:

<txp:article my_custom_category_field='<txp:category />'>
	<txp:title />
	<txp:body />
</txp:article>

But how can I make a contains-search as a value to my_custom_category_field="" ?,
for example my_custom_category_field='*_<txp:category />', is there a magic code for that please?

Last edited by THE BLUE DRAGON (2016-09-03 08:28:41)

Offline

#4 2016-09-03 08:41:32

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

Re: Categories and clean URL

THE BLUE DRAGON wrote #301003:

But how can I make a contains-search as a value to my_custom_category_field="" ?,
for example my_custom_category_field='*_<txp:category />', is there a magic code for that please?

Try <txp:article my_custom_category_field='%\_<txp:category />'>...

Offline

#5 2016-09-03 09:35:41

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Categories and clean URL

etc wrote #301004:

Try <txp:article my_custom_category_field='%\_<txp:category />'>...

Thanks! :)
It works in a article_custom tag, but not in a regular article tag, because there aren’t any articles with real categories.
When using artilce_custom tag it’s not showing the full list when there’s no category in the URL, so I’m using txp:if_category together with a form and a variable like so and it works:

<txp:variable name="filter_categories" value="" />
<txp:if_category>
	<txp:variable name="filter_categories" value='%\_<txp:category />' />
</txp:if_category>
<txp:article_custom section="my_section_name" form="article_content_form_name" my_custom_category_field='<txp:variable name="filter_categories" />' />

Is it good or we can improve it please?

Last edited by THE BLUE DRAGON (2016-09-03 09:36:53)

Offline

#6 2016-09-03 09:45:08

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

Re: Categories and clean URL

THE BLUE DRAGON wrote #301005:

Is it good or we can improve it please?

Looks fine for me, you can just shorten it:

<txp:variable name="filter_categories"
	value='<txp:if_category>%\_<txp:category /></txp:if_category>' />

Edit: no need for <txp:else />

Last edited by etc (2016-09-03 10:09:25)

Offline

#7 2016-09-03 09:50:16

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Categories and clean URL

etc wrote #301006:

Looks fine for me, you can just shorten it:

Oh right! LOL
I will change the variable to a container tag for it be more comfortable (at least for me).
Thanks :)

Offline

Board footer

Powered by FluxBB