Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-25 16:49:48

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

List problem

Hi,

I’ve tied myself in knots trying to organise my lists. What I want to do is list articles separated by category, each category block should then be contained within a <div> called ‘module’ – but I can’t get it to work correctly. Here’s what I have so far:

Page code:

<txp:article_custom pgonly="0" section="garden-projects" form="gbd_articleListing" sort="Category1,posted desc" status="4" break="div" class="module" />

Form:

<txp:if_different>
   <h4><txp:category1 title="1" this_section="1" /></h4>
</txp:if_different>
   <ul class="listing">
      <li><txp:permlink><txp:title /></txp:permlink></li>
   </ul>

Would really appreciate any help.

Offline

#2 2009-08-25 17:06:15

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

Re: List problem

decoderltd wrote:

What I want to do is list articles separated by category, each category block should then be contained within a <div> called ‘module’

Something like this?

<txp:category_list>
	<div class="module">
	<h4><txp:category title="1" /></h4>
	<txp:article_custom section="garden-projects" category='<txp:category />' wraptag="ul" class="listing" break="li">
 		<txp:permlink><txp:title /></txp:permlink>
	</txp:article_custom>
	</div>
</txp:category_list>

Last edited by els (2009-08-25 17:06:54)

Offline

#3 2009-08-25 17:36:32

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: List problem

Hi Els,

Thanks, that’s great, almost there – it’s behaving styling-wise but seems to be in a loop and is listing all category headers rather that section sensitive ones – I’ve put the site online so you can see what I mean.

To allow the code to work across all pages could your snippet be tweaked so section='<txp:section />'?

Offline

#4 2009-08-25 18:10:33

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: List problem

What code are you using now? Its repeating 8 times, so I would try what you suggest first, then see if that works.

Offline

#5 2009-08-25 18:29:55

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: List problem

Hi Jonathan,

Okay, I think the repeating was a problem with too many nested forms so I’ve simplified things. The only problem now is that all category heading are being display although it’s only showing the section articles. The code is much as Els suggested but with the section tag amended -

<txp:category_list>
   <div class="module">
   <h4><txp:category title="1" /></h4>
   <txp:article_custom section='<txp:section />' category='<txp:category />' wraptag="ul" class="listing" break="li">
   <txp:permlink><txp:title /></txp:permlink>
   </txp:article_custom>
   </div>
</txp:category_list>

Offline

#6 2009-08-25 18:57:04

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

Re: List problem

decoderltd wrote:

The only problem now is that all category heading are being display although it’s only showing the section articles.

That can probably be solved by checking if there are articles in that particular category and in the current section:

<txp:category_list>
   <txp:variable name="has_articles" value='<txp:article_custom section=''<txp:section />'' category=''<txp:category />'' limit="1" />
   <txp:if_variable name="has_articles" value="">
   <txp:else />
   <div class="module">
   <h4><txp:category title="1" /></h4>
   <txp:article_custom section='<txp:section />' category='<txp:category />' wraptag="ul" class="listing" break="li">
   <txp:permlink><txp:title /></txp:permlink>
   </txp:article_custom>
   </div>
   </txp:if_variable>
</txp:category_list>

Last edited by els (2009-08-25 18:58:46)

Offline

#7 2009-08-25 18:57:12

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: List problem

Looks ok to me – do you want more than one section to be called? If so, why not use something like:

   <txp:article_custom section="section1,section2" category='<txp:category />' wraptag="ul" class="listing" break="li">

Maybe I am missing what you need..?

Offline

#8 2009-08-25 18:58:41

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: List problem

Or use variables to get at what you need if you want to check if an article exists in a particular section.

Offline

#9 2009-08-25 19:00:49

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: List problem

Look like Els was quicker – as usual ;-) By the way, where did you create your favicon for the site? Looks really nice.

Offline

#10 2009-08-25 19:34:04

decoderltd
Member
From: London
Registered: 2006-06-20
Posts: 248
Website

Re: List problem

Hi Els,

Thanks for posting the revised code, I’m afraid it still didn’t work and made the page load very slowly. I’ve looked through everything several times but can’t see what I’ve done wrong – the page is listing category headings that aren’t in that section, but on the plus side it is listing the correct articles (it should only list Projects and Testimonials), so I just need to figure why it’s behaving that way.

Thanks for your comment on the favicon Jonathan, just something I threw together in Illustrator – as you can see, my design skills are slightly better than my coding!

Offline

#11 2009-08-25 20:12:14

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

Re: List problem

Hi decoderltd, I don’t see right away what could be wrong. Can you post a tag trace of the page with my code on it? (I assume you took it out again, because it seems to load fast enough now…)

Offline

#12 2009-08-25 20:35:07

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: List problem

The favicon is nice – but it is the quality that is really good – how did you create the actual .ico file? Which app or website?

Offline

Board footer

Powered by FluxBB