Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2018-03-09 10:46:53

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,031
Website

Re: URL's like section/cat1/title

catonine wrote #309841:

well, I rephrase

I want simply thing: urls like
http://sitename/earth/country/town/city/my_street

Hmm, and I suspect you want every step of that URL to show the relevant options (I wonder what other options there will be alongside “earth”, or are you joking here? Similarly, how will you differentiate between town and city). If you really want that level of granularity, you’ll need to carefully map out your internal structure first, how you are going to record these pieces of information in your articles and work out how your page templates will respond to each level.

The method I showed above is no use for your desired structure as you’d be constantly updating the RewriteRule to accommodate all the new locations and variants. That is only a practical approach if the site structure remains relatively constant.

First, I suggest you use url variables, e.g. ?country=italy&city=rome&street=via-regia and use rah_gps or adi_gps to retrieve each of these from the URL and convert them into Textpattern variables. Then you will need to develop a series of tag constructions for your page to respond to each combination of variables (e.g. what happens when one is missing).

You can use the variables as attributes for other tags by wrapping them in single quotes, e.g. txp:article_custom category='<txp:variable name="country" />' … /> means process the value of the variable and use it as the category filter. I expect you may find it more useful to store this information as custom fields in your article rather than as deep category tree as it will make it easier for you to construct your custom URLs… otherwise you’ll need to be always recursively determining parent and child categories to construct your urls. You may find with this level of complexity that it is more practical to build direct DB queries directly using smd_query or etc_query than to have numerous article_custom and if_category steps.

And … once you have all that working satisfactorily, you can then build your .htaccess RewriteRule to make clean urls translate to the URL variables, and adapt your custom link-constructing tag accordingly…

Unless “etc” can think of some clever system of recursive nested forms (have a look through the forum for a few recent examples) I can’t think of another good way at the moment.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2018-03-09 11:10:22

etc
Developer
Registered: 2010-11-11
Posts: 2,778
Website

Re: URL's like section/cat1/title

I suspect that currently txp will not work well with identical article titles within a section, so you’ll need to somehow append ID to your custom URLs:

http://sitename/earth/country/town/city/my_street/22
jakob wrote #309847:

First, I suggest you use url variables, e.g. ?country=italy&city=rome&street=via-regia and use rah_gps or adi_gps to retrieve each of these from the URL and convert them into Textpattern variables.

I agree, it’s easier to start in messy mode and adapt .htaccess once everything is working. In 4.7 <txp:page_url type="country" /> can retrieve URL country (sanitized) value too.

I expect you may find it more useful to store this information as custom fields in your article rather than as deep category tree as it will make it easier for you to construct your custom URLs…

Not necessarily, <txp:breadcrumb /> can be of rescue here, at least in 4.7. For example, this link in an article form

<a href="<txp:site_url /><txp:breadcrumb category='<txp:category1 />' separator="/" wraptag="" label="" link="" />/<txp:article_url_title />/<txp:article_id />">
    <txp:title />
</a>

and this .htaccess rule (before the supplied one)

RewriteRule ^.+/(\d+)$ index.php?id=$1 [L]

should work.

Last edited by etc (2018-03-09 14:22:29)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#13 2018-03-13 09:04:36

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 3,031
Website

Re: URL's like section/cat1/title

Found this by chance: rah_pathway, which is on github (still uncompiled, so you need to compile it with ied_plugin_composer or use it via the plugin cache directory).

It’s not a solution to your problem as a whole, and doesn’t change the organisational paradigm of textpattern – i.e. it only catches the endpoint of the url, not the various /-steps in-between, and redirects that behind the scenes to the article’s actual location. Effectively it helps you spoof your subsection urls without providing any actual subsection support.

There are other redirect plugins such as smd_redirect and arc_redirect (more recent on github) but those have a separate tab for managing redirects. rah_pathway stores its information with the article in a custom_field (you have to edit the plugin source to tell it which one to use), which means you can also use that custom field to build your links to the article in place of txp:article_url_title. smd_short_url is another plugin that works using a similar principle.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB