Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-12-16 23:05:40

oldi
Member
Registered: 2005-10-14
Posts: 87

show only the last 5 categories

I have a long list of categories corresponding to monthly issues. SO, i don’t want to show all of them by using the category_list cos i will end up with a very long list. Is there a way of showing only the last 5 categories?

thanks

Offline

#2 2005-12-17 01:43:55

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: show only the last 5 categories

I haven’t tried this oldi but…. Create a new FORM template called something like latest_issues with code like this:-

<code>
<txp:if_different>
<li><a href=”<txp:site_url />?c=<txp:category1 />”><txp:category1 title=“1” /></a></li>
</txp:if_different></code>
<br />

which should pull out all of the categories. There are going to be ones you don’t want so we sort that out in the page template code which would go something like:-

<code>
<ul>
<txp:article_custom form=“latest_issues” limit=“5” section=“sectionName” sortby=“Category1” sortdir=“desc” />
</ul></code>
<br />

So we call the new form and limit the output to 5. The section will limit us to the proper section for this then we sort by Category1 and we could add Posted as well if need be, and the bit I’m not sure about is whether “sortdir” should be desc or asc but try it out and see what happens. The formatting tags will give you an unordered list assuming anything appears at all. :)

Last edited by thebombsite (2005-12-17 01:51:42)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#3 2005-12-17 02:59:53

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: show only the last 5 categories

Nice.

Offline

#4 2005-12-17 08:06:12

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: show only the last 5 categories

Thank you. Should wait until he’s tried it first though. ;)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#5 2005-12-17 22:09:11

oldi
Member
Registered: 2005-10-14
Posts: 87

Re: show only the last 5 categories

You’re the man!!!

It worked perfectly.

Just one question, you mentioned section=“sectionName”. I wasn’t sure what to put for section name so have put section=” “. Thinking this will give me the results in every section. It is working but just wandering is this right? Also i have noticed that when i put the limit to 5 i get only 3 categories showing, i change to 10 and get 8. I don’t get it, but it seems that something else is interfering. It’s not a massive problem, since i can always put the limit to 7.

A final question. Is there a way of hiding just one category by using the same technique. I have lots of Issue categories and just one News category. It is a bit annoying to have the News category showing with the rest. I know i can use wow_menu plugin but as i mentioned in its post, i am having a bit of problem with the plugin, so just wandering whether can be done in any other way.

thanks a lot for you help. It is very clever.

Offline

#6 2005-12-17 22:20:37

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: show only the last 5 categories

Well if you want to include every section then you don’t need the attribute at all. It’s just that unlike <code><txp:article /></code>, the <code><txp:article_custom /></code> tag isn’t “context-sensitive” so if you did only want categories from a single section you would need to specify it.

I’m not sure why the “limit” is behaving oddly. Maybe something else you have in the page template? Are you using the <code><txp:pageby /></code> tag anywhere?

Off-hand I can’t think of a way of hiding a category with this method other than using the “offset” attribute in the article tag, but that would only work if it happened to be first in the output list which I doubt it is??

I’ll think about that some more.

Last edited by thebombsite (2005-12-17 22:32:28)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#7 2005-12-17 23:33:53

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: show only the last 5 categories

The limit doesn’t specify how many categories to list, but rather how many posts to check when making your category list.

Don’t forget that if you use article instead of article_custom, that you may need to make some adjustments with regards to comments (turn off auto-append).

Offline

#8 2005-12-17 23:56:45

oldi
Member
Registered: 2005-10-14
Posts: 87

Re: show only the last 5 categories

I don’t think i have pageby tag. Below is my page template. I have included the code in the form Temp_sidebar.

I have noticed that if i put sortdir=“asc” i get only one category showing instead of 5. That is wired cos i remember trying that and it was working allright. I might have done something by mistake and can’t remeber at the moment. SO now, i don’t have to put sortdir at all, and i get the categories listed desc. I am getting a bit confused. Also i was experimenting with offset. But it seems that if i do offset=“1” will add an extra category showing, so i will get 6 categories showing or 2 categories if i do sortdir=“asc”. I thought that offset will just skip one category but still keep the number of shown categories the same. i am really getting confused.

this is my page template

<code><txp:output_form form=“Temp_header” />
<body id=“home”>
<txp:link_to_home><div id=“header”></txp:link_to_home>

</div>

<div id=“wrapper”> <div id=“container”> <div id=“content”> <div class=“contentdiv”> <div class=“divweblog”>

<txp:if_search>
<h2 class=“searchtitle”>Your Search Results</h2>
<txp:article limit=10 pgonly=1 />
<h2 class=“searchtitle”><txp:search_result_count /> for “<txp:q />”</h2>
<br />
<div id=”<txp:section />”>
<txp:article limit=“10” />
</div>
<txp:else />
<txp:if_category>
<txp:article form=“Single” status=“sticky” limit=1 />
<txp:article limit=“99” />
<txp:else />
<txp:article_custom section=“about” form=“Single” status=“sticky” limit=1 />
<txp:article_custom category=“news” limit=“99” />
</txp:if_category>
</txp:if_search>

<txp:if_individual_article>
<txp:article />
<p>
<txp:link_to_prev><txp:prev_title /></txp:link_to_prev>
<txp:link_to_next><txp:next_title /></txp:link_to_next>
</p>
</txp:if_individual_article>
<txp:if_article_list>
<p>
<txp:older>Previous</txp:older>
<txp:newer>Next</txp:newer>
</p>
</txp:if_article_list>

</div> </div> </div> </div>

<txp:output_form form=“Temp_sidebar” />

<div class=“clearing”>&nbsp;</div>

<div id=“footer”></div>
</body>
</html>
</code>

this is my Temp_sidebar form

<code>
<div id=“sidebar”>
<div class=“sidebardiv”>

<div class=“sidebarbody links”>
<h3>Menu</h3>

<ul>
<li><a href=“http://www.morava.f2s.com/bsms/”>About Us</a></li>
<li><a href=“http://www.morava.f2s.com/bsms/contact”>Contact Us</a></li>
</ul>
</div>

<br />

<div class=“sidebarbody categories”>
<h3>Categories</h3>
<div class=“sidebarin”>
<ul>
<txp:article_custom form=“latest_Issue” limit=“7” sortby=“Category1” />
</ul>

</div>
</div>
<br />

<div class=“sidebarbody search”>
<h3>Search</h3>
<txp:search_input section=“search” button=“Go” label=”“ wraptag=“p” />
</div>
<br />

<div class=“sidebarbody opinions”>
<h3>Opinions</h3>
<txp:pap_xpoll poll=“1” />
</div>

</div>
</div></code>

Offline

#9 2005-12-18 00:14:53

oldi
Member
Registered: 2005-10-14
Posts: 87

Re: show only the last 5 categories

Thanks Mary. After reading your post it makes sense why sortdir=“asc” is showing only one category. My first category has more than 7 posts so when i put the limit to 7 it will show only that category. Its all clear now. Also that explains why is not showing the categories that don’t have any posts, which i thought it was a good feature.
But is there a way that the limit is linked with the number of categories rather than the number of posts. Since, i will have to change this limit every time the number of posts changes.

thanks

Offline

#10 2005-12-18 00:58:11

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: show only the last 5 categories

Damn. That little detail didn’t register with me either. See. Even I get to learn something. :)

I can’t see a way out of that. I’m presuming that if you use the “output_form” tag instead of “article_custom” you will end up with a complete category listing and I can’t think of a way of controlling that either.

Back to the drawing board methinks.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

Board footer

Powered by FluxBB