Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-06-27 14:20:39

got10thumbs
New Member
Registered: 2011-03-27
Posts: 5

how use the link parameter

I want to make a list-and-detail page for a pet club but I’m having trouble with understanding links. One page should list kinds of pet (cats, dogs, birds, etc), where clicking ‘cats’ goes to a page listing all the pet cats in the club (Felix, Hodge, etc), and clicking Hodge should go to a page with info about the cat Hodge.

I’m using category ‘Pets’ for kinds of pet, with child categories ‘cat’, ‘dog’ etc . I have articles called Hodge, Felix, etc, each in a section called ‘a_pet’; and an article called ‘types of pet’ in section ‘list of pets’, associated with a page called ‘show pet types’. That page contains this code:

<txp:category_list wraptag="ul" break="">
    <li>
        <txp:category title="1" link="1" />
    </li>
</txp:category_list>  

When I view the article called ‘types of pet’ I duly get a list of pet types, each of which links to the section ‘list of pets’ with a URL parameter to show what of pet: https://XXX/txtpat/list-of-pets/?c=bird etc. But when I click on the link it just goes to the same page.

How do I make use of the URL parameter (that is, c=bird, etc) to get a list of pets of that type?

I can’t find the relevant info in the documentation not in the forum, though i may have searched for the wrong thing. Apologies if this has been ansered previously.

Offline

#2 2022-06-27 16:06:19

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

Re: how use the link parameter

Hmmm, the way you describe it is exactly the way it is supposed to work. So my guess is there is something not quite right with your page template or list tag. If you put the article ‘types of pet’ in the same section as your pets, it’ll work. Or tell your category_list tag to consider articles from another section by using the section="a_pet" attribute.

The reason it’s not working is that your category links are defaulting to the current section (‘list_of_pets’), your <txp:article> tag is then looking for articles in that section with categories assigned to them and not finding any (since they’re in the ‘a_pet’ section).

I set up something in my test site like this, so you can compare it to yours:

Section: a_pet
Page: show_pets contains this code in its page template somewhere:

<txp:if_category>
    <h1 itemprop="name"><txp:text item="category" /> <txp:category title /></h1>
</txp:if_category>
...
<txp:article limit="100" wraptag="ul" class="article-list" />

Article: types_of_pet (also in section: a_pet) contains this code (with Textile formatting turned off) :

<txp:category_list wraptag="ul" break="" parent="pets" exclude="pets">
    <li>
        <txp:category title="1" link="1" />
    </li>
</txp:category_list>  

Visiting example.com/a_pet/types_of_pet renders a list of all child categories under the Pets category (excluding itself).

Each of those links goes to a URL like this: example.com/a_pet/?c=dogs

And clicking it then displays the H1 heading of the category, followed by a list of articles of pets with names in the chosen category.

Depending on your desired use case, you might want to make your ‘list of pets’ article a Sticky article. Then you can tweak your page template so it displays that article only if you’re on the base landing page, and omit it if you have clicked an actual category name or are viewing a pet article.

Another approach is to put the category_list tag in your page template: again, use some conditional tags to determine if the page context is NOT category and NOT an article, and if so just display the list of categories. Then you can do away with your ‘type of pets’ article entirely.

The latter approach will make use of built-in ‘clean URL’ category links such as example.com/category/dogs and have it display the matching articles. That’s the prettiest URL solution as it renders them without question mark parameters, but it depends on what you want your URLs to look like.

Hope that helps but please ask questions if it’s not clear and we’ll try and help you figure out the best path.

Last edited by Bloke (2022-06-27 16:20:49)


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 2022-06-28 05:49:38

got10thumbs
New Member
Registered: 2011-03-27
Posts: 5

Re: how use the link parameter

Works beautifully. Many thanks Bloke – not just for fixing it, but also for a careful, clear, non-patronising explanation.

Offline

Board footer

Powered by FluxBB