Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-02-21 16:24:35

carlahearne
Member
From: Milton Keynes, UK
Registered: 2011-11-13
Posts: 29
Website

Creating the appearance of sub-sections.

Hi guys,

I’m scratching my head a little here and I’m wondering how I might acheive the following:

I have a site with sections which works nicely. Within 1 of those sections, I’d like to have sub-sections. eg. Parent Section is Products. Within that I’d like to split into Type 1, Type 2, Type 3 etc. Each of those would then list the actual products which would be an article.

Am I better to do this with categories?

What I want – When I go to the section Products, it produces a list of the types i.e Type 1, Type 2 etc. Clicking on those would take me to a list of articles for each of the product types.

Linked to this problem, can I have different page templates for each part i.e on the Products page I use the product page templete. when I click on the type, I want to use the Type page template? I notice that by default any time you click on a category, you get the default page template.

To sum up, I’d like my URL to look something like www.domain.co.uk/products/type/productname
What I don’t really want is www.domain.co.uk/category/type/productname which is what categories seem to force me into…

I hope that makes sense; it’s quite hard to explain what I want…

Any help greatly appreciated.

Carl

Offline

#2 2013-02-21 21:28:01

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Creating the appearance of sub-sections.

If your types are categories, you can use gbp_permanent_links to have URLs like /products/type/ (/sectionname/categoryname/) and /products/type/productname (/sectionname/categoryname/articletitle).

It is not possible to use two different page templates for one section, but you could use conditional tags in the Products page template to render different layouts depending on the context:

<txp:if_category>
  <!-- category/type page, list of articles/products in this category -->
  <txp:body>
    // the code that is now on your Type page
  </txp:body>
<txp:else />
  <!-- either individual article page or Products main page with list of categories/types -->
  <txp:body>
    // the code that is now on your Products page
  </txp:body>
</txp:if_category>

On the Products main page you can use the category_list tag to create a linked list of categories/types and an article tag to display the products (articles) in a category. A simplified example:

<txp:if_article_list>
  <!-- list of all types -->
  <txp:category_list this_section="1" />
<txp:else />
  <!-- individual article/product page -->
  <txp:article />
</txp:if_article_list>

The this_section="1" will link to the current section (in this case Products) instead of displaying the category page on the front page, which is the default behaviour.

Note that if you also want to display a search results page on the Products page, you’ll need some more conditional tags.

Offline

#3 2013-02-22 10:46:50

carlahearne
Member
From: Milton Keynes, UK
Registered: 2011-11-13
Posts: 29
Website

Re: Creating the appearance of sub-sections.

Thanks for the help Els, that all seems to make sense..

I now seem to be having a different problem; articles belonging to a category don’t seem to be showing up at all…

I’ve tried using the default textpattern tags and I’ve also tried with the rss_unlimited_categories plugin as per below:

<txp:if_category> <h1><txp:category title=“1” /></h1> <txp:rss_unlimited_categories_article_list section=”*”/>
<txp:else /> <!—Home page code here—>
</txp:if_category>

I’m going to www.domain.co.uk/categories/categoryname1 and the title is showing as expected but no articles and I have no idea why; it should be showing me a list of articles belonging to categoryname1 right?

Any help would be great…

Offline

#4 2013-02-22 12:25:27

carlahearne
Member
From: Milton Keynes, UK
Registered: 2011-11-13
Posts: 29
Website

Re: Creating the appearance of sub-sections.

OK, please ignore the above.. I’d installed rss_unlimited_categories and hadn’t yet run the SQL to asign the existing categories so the reason it wasn’t displaying the articles is because there were none! I should check more carefully next time…

Offline

#5 2013-02-22 19:43:26

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: Creating the appearance of sub-sections.

<txp:if_individual_article> and <txp:if_article_list> are useful for adding logic to templates. I tend to use them quite often. And you can really creative if you add in <txp:if_first_article> and <txp:variable />.

Last edited by michaelkpate (2013-02-22 19:46:51)

Offline

Board footer

Powered by FluxBB