Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-29 18:30:40

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Category linked to a section, with subcategories ... and breadcrumb

Hello all,

I’m working on a website which has sections, and for each section is linked a particular set of category and subcategories. To link the parent category with its section, I used the same name for both (no matters the title).

For example, the section named ‘products’ displays these categories :
  • products
    • motherboards
      • intel-mini-atx
      • intel-s-478
      • intel-s-775
    • hard disks
      • 2-5
      • 3-5
      • external
What I want to do is
  • display a breadcrumb like : products > motherboards > intel-s-775 but linked with the section and not the category (a sort of <txp:breadcrumb this_section="1" />) where ‘products’ is the section, ‘motherboard’ and ‘intel-s-775’ are the [sub]categories. In other words, the parameters in the links should be (when using messy urls) : /?s=products > / ?s=products&c=motherboards > /?s=products&c=intel-s-775
  • when browsing the category ‘motherboard’, have a list of all the products in its subcategories

A product can be in 2 different categories.
There could be later more levels of subcategories.

My questions are :
  • is it possible natively ? (unsure …)
  • can I find plugin(s) to do this ?
  • or should I write mine ? :p

Hope I’ve been clear.

Thank you !

Offline

#2 2011-04-29 22:04:18

brunodario
Member
From: Belo Horizonte, Brasil
Registered: 2007-09-19
Posts: 75

Re: Category linked to a section, with subcategories ... and breadcrumb

For the breadcrumbs:

You´ll need etz_crumbs this plugin it´s a great aid for breadcrumbs. Your code will look something like this:

<p class="crumbs"> You are here: <txp:etz_crumbs hometitle="Home Page" category="2" /> </p>

Using your example this will output

You are here: Link to home page > Link to Section (Products) > Link to Category1 (products) > Link to Motherboards > Link to intel-mini-atx

The drawbacks:

First

you´l have a repeated link with same name ( Products link to section > Products link to category > etc…) .

One way to deal with it it´s by editing the category “Products” (and any other master category) and leave the Title field blank. This will make the name disapear, leaving the breadcrumb with 2 “>” symbols. Or you can remove the third link with jquery, something like:

$('p.crumbs a:eq(2)').remove();

If you opted for the first solution you may also be able to get rid of the doubled “>” with jquery.

Second

Using your example: The way textpattern deals with category doesn´t allow a user to click on “Motherboards” category and have “Intel-mini-atx” , “intel-s-478” and “intel-s-775” listed. So this is a situation i haven´t found any other solution but listing it manually (in my case it wasen´t a crucial thing because the main and second level sections were fix but this can be a serius issue if your site is so dynamic that the categories change every time).

Anyway a form to list it manually would look something like this:

Create a form called “global_categories”
<txp:if_category name="motherboards"> <txp:article_custom form="yourform" category="intel-mini-atx, intel-s-478, intel-s-775 " limit="99" section="products" /> </txp:if_category> .... repeat for other categories

And then call it anywhere: <txp:output_form form=“global_categories”/>

If anyone knows a way to achieve this dynamically i´ll apreciate it too! Hope it helps you anyway…

Offline

#3 2011-04-30 14:33:16

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Category linked to a section, with subcategories ... and breadcrumb

brunodario a écrit:

You´ll need etz_crumbs this plugin it´s a great aid for breadcrumbs.

Yes, it helps, thank you.
I’ll have to deal with the double “Products” and the presence (or not) of a second category, but it shoudn’t be a problem.

The way textpattern deals with category doesn´t allow a user to click on “Motherboards” category and have “Intel-mini-atx” , “intel-s-478” and “intel-s-775” listed. […] this can be a serius issue if your site is so dynamic that the categories change every time.

Ok. The site won’t be that dynamic, but I prefer to be pro-active :) and manage the category tree automatically from the beginning.
So, researches keep going on !

Offline

#4 2011-04-30 16:18:30

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: Category linked to a section, with subcategories ... and breadcrumb

brunodario a écrit:

The way textpattern deals with category doesn´t allow a user to click on “Motherboards” category and have “Intel-mini-atx” , “intel-s-478” and “intel-s-775” listed.

Actually, yes … almost.

To retrieve in a variable (named “allcats” in the example) a comma-separated list of the current category and all its subcategories, in one line :

<txp:variable name="allcats" value='<txp:category_list parent=''<txp:category />'' break=","><txp:category /></txp:category_list>' />

Notice the double single quote around <txp:category />

Offline

Board footer

Powered by FluxBB