Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-06-24 10:39:40
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Create category page
On a website I have a section “projects”. On that page, there is a list of all the projects, with links to the individual pages for each project. The list of projects is getting too long to show on one page, so we want to start using categories.
The goal is to have on the page “projects” (with URL /projects/), a list of categories for those projects. Say we have 10 categories of projects. Now clicking on a category should lead to a page with a list of projects within that category. And then clicking on one project leads to the page about that project.
What I have done so far, is create a page with the following
<div id=“content” class=“default”>
<txp:category_list parent=“projects” break=“li” wraptag=“ul” />
</div>
That gives a nice list of the project categories within the section projects. However, clicking on one of the categories brings me to the URL /category/somecategory, but that page doesn’t return anything. How can I make it so that clicking on a category shows the list of projects in that category? And then clicking on the individual projects shows the individual project?
Offline
Re: Create category page
See Tag Reference:
The <txp:category_list>
has an attribute called this_section
. It also can be used as a container if you need customized output.
For example the container feature:
<txp:category_list parent="projects" this_section="1">
<li>
<a href="<txp:site_url />projects/?c=<txp:category />">
View <txp:category title="1" />
</a>
</li>
</txp:category_list>
The txp:article
is context sensitive and can be used to output the articles in the category view.
Last edited by Gocom (2009-06-24 11:25:24)
Offline
#3 2009-06-24 12:48:55
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Re: Create category page
Thanks for your reply. However, your code does not do anything different then what I already had. It shows a list of links to the categories in the section projects.
I did that already with
<txp:category_list parent="projects" break="li" wraptag="ul" />
which gives me as output
<ul class="category_list">
<li><a href="http://www.mysite/categorie/projects/">Projects</a></li>
<li><a href="http://www.mysite/categorie/houses/">Houses</a></li>
<li><a href="http://www.mysite/categorie/castels/">castels</a></li>
</ul>
However, clicking on the links doesn’t lead me anywhere. Neither with your code nor with mine.
Offline
Re: Create category page
matthijs wrote:
Thanks for your reply. However, your code does not do anything different then what I already had. It shows a list of links to the categories in the section projects.
My code? The container example? Yes it does. My container example outputs urls of form:
<txp:site_url />projects/?c=<txp:category />
matthijs wrote:
However, clicking on the links doesn’t lead me anywhere. Neither with your code nor with mine.
Yes it leads. It leads to the front page (section default) and category set to the selected category. If you want to link to the projects section, you need to select the section.
By reading the tag refrences I linked you see that there are additional attributes too, for example a section
, and this_section
. Other is used as a filter and a second in the link itself. With container you can customize the output, other than the break tag.
Offline
#5 2009-06-24 13:43:32
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Re: Create category page
Yes, both your code and my code display a list of those links
<ul class="category_list">
<li><a href="http://www.mysite/categorie/projects/">Projects</a></li>
<li><a href="http://www.mysite/categorie/houses/">Houses</a></li>
<li><a href="http://www.mysite/categorie/castels/">castels</a></li>
</ul>
However, clicking on them results in seeing the homepage. I shouldn’t see the homepage, I want to see a page with a list of the projects within the category. For example, after clicking “houses”, I should see a list of the projects with the category houses.
Maybe I should clarify further. We have a website with a few sections, which make up the main navigation.
/
/projects
/about-us/
/contact/
So one of those sections is “Projects”. Now when I click on Projects, I get to see the list of available categories of projects:
/projects
<a href="/projects/houses/">Houses</a><br>
<a href="/projects/castels/">Castels</a><br>
<a href="/projects/pensions/">Pensions</a><br>
or if that is not possible,
<a href="/category/houses/">Houses</a><br>
<a href="/category/castels/">Castels</a><br>
<a href="/category/pensions/">Pensions</a><br>
Now clicking on any of those links, leads us to the next page, with a list of projects within that category. For example when clicking on castles:
/projects/castles/
<a href="/projects/castle-on-the-rock/">Castle on the Rock</a><br>
<a href="/projects/castle-on-the-hill/">Castle on the hill</a><br>
<a href="/projects/castle-of-the-queen/">Castle of the queen</a><br>
Hope it is clear what I want to achieve?
Offline
#6 2009-06-24 14:15:25
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Re: Create category page
Update: I just created a new, clean install of Textpattern to test some things. I did:
- create a new section projects
- create a new page projects
- create a new category “Castles”
- create a new article “Castle of the Hill”, and gave it category Castles and section Projects
Next, I put this in the page projects
<div id="content">
<ul>
<txp:category_list parent="projects" this_section="1">
<li>
<a href="<txp:site_url />projects/?c=<txp:category />">
View <txp:category title="1" />
</a>
</li>
</txp:category_list>
</ul>
</div>
However, now nothing at all shows up when I click on /projects/
What am I missing?
Offline
#7 2009-06-24 17:28:44
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Create category page
matthijs wrote:
However, now nothing at all shows up when I click on /projects/
Do you mean not even your category menu?
What am I missing?
You also need a <txp:article />
tag on your ‘projects’ page to display the articles in the requested category. Do you have one? Can you post the full code on that page?
Edit: something like the code example in this Textbook article should work.
Last edited by els (2009-06-24 17:31:54)
Offline
#8 2009-06-24 19:26:17
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Re: Create category page
Thanks for your help.
Do you mean not even your category menu?
No, nothing at all.
The full code in the page (next to some other html) is
<div id="content" class="default">
<div class="inner">
<ul>
<txp:category_list parent="projects" this_section="1">
<li>
<a href="<txp:site_url />projects/?c=<txp:category />">
View <txp:category title="1" />
</a>
</li>
</txp:category_list>
</ul>
</div>
<div class="bottom"></div>
</div>
I don’t have the txp:article in there. Is that needed? I only want to show a list of the categories, like I showed in my previous post.
I’ll check out the article you linked to.
Offline
#9 2009-06-24 19:40:28
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Create category page
matthijs wrote:
No, nothing at all.
Did you assign your page ‘projects’ to section ‘projects’? (Presentation > Sections)
Do your categories really have a parent category ‘projects’?
I don’t have the txp:article in there. Is that needed? I only want to show a list of the categories, like I showed in my previous post.
Sorry, I don’t get why you are linking to /projects/?c=category then. What is supposed to be on those category pages if you don’t want to display the articles in the category?
Anyway, I think we’ll be able to see more – and understand better – if you’d post a tag trace.
Offline
#10 2009-06-24 20:03:55
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Re: Create category page
Ok, I redid everything and changed the page code from
<ul>
<txp:category_list parent="projects" this_section="1">
<li>
<a href="<txp:site_url />projects/?c=<txp:category />">
View <txp:category title="1" />
</a>
</li>
</txp:category_list>
</ul>
to just
<txp:category_list parent="projects" break="li" wraptag="ul" />
and now I get a list of categories within the section projects (categories which are children of parent category projects).
<ul class="category_list">
<li><a href="http://textpattern/category/projects/">Projects</a></li>
<li><a href="http://textpattern/category/boerderijen/">Boerderijen</a></li>
<li><a href="http://textpattern/category/kastelen/">Kastelen</a></li>
</ul>
Now what is left to do is get rid of that first link, http://textpattern/category/projects/ which I don’t want to have there.
About why I had /projects/?c=category in there: that was the code snippet Gocom posted.
About the tag trace: that’s a nice feature! I have put it on. Now that it seems to display the category list fine, I don’t see any errors
Offline
#11 2009-06-24 20:57:22
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Create category page
matthijs wrote:
Now what is left to do is get rid of that first link, http://textpattern/category/projects/ which I don’t want to have there.
<txp:category_list parent="projects" exclude="projects" break="li" wraptag="ul" />
Offline
#12 2009-06-24 22:01:24
- matthijs
- Member
- Registered: 2008-12-15
- Posts: 32
Re: Create category page
Thanks Els, that’s it. That category listing is working now.
I think I’ve got it all working now. Have to check everything tomorrow :)
Offline