1 of 6
1
New “Subcategories” plugin available.
Posted: 28 September 2005 04:56 AM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

I’ve written an EE plugin that will let you show a list of subcategories for a given category. I call it the “Subcategories” plugin. It’s attached to this post as “pi.subcategories.txt”. To use the attachment (save it into your plugin folder and) rename it to pi.subcategories.php.

Please try it out and give me your feedback about bugs etc. I plan to add the final version to the ExpressionEngine’s list of plugins for EE if you like. Thanks.

File Attachments
pi.subcategories.txt  (File Size: 19KB - Downloads: 1078)
 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 28 September 2005 05:22 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  12433
Joined  04-29-2002

Since I’m assuming you’re going to be using this for breadcrumbs of some sort… there isn’t anything that can be displayed if there are no results.

Other than that, it worked just fine!

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 28 September 2005 08:19 AM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

MF, great plugin - I know how many times this has come up. wink  One thing I’d suggest, if it’s not hard to add - adding the category description, and the category image as variables.  I only had a quick scan through the docs but didn’t see those there.

 Signature 
Profile
MSG
 
 
Posted: 28 September 2005 10:48 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9868
Joined  06-19-2002

The parameter for setting the “order” of the categories doesn’t seem to have an option for respecting the custom order that someone may have used under ‘Admin > Category Management’.  The custom order could be different than both the alphabetical order and the order of category IDs.

 Signature 

Chris Curtis
chriscurtis.org

Profile
 
 
Posted: 28 September 2005 12:34 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

@Sue

You’re right. If a category doesn’t have any subcategories, nothing will be shown. That’s intentional.

@Lisa

I’ve added both variables {category_description} and {category_image}.

@Chris

I’ve added the value “custom_order” to the “sort_by” parameter. It will let you sort the subcategories by the same custom order you chose in the Admin section.

See the new attachment for this new version.

Thanks for all your feedback. Don’t hesitate to add more to it.

File Attachments
pi.subcategories.txt  (File Size: 21KB - Downloads: 813)
 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 28 September 2005 02:24 PM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

You rock.  I have to write a paper tonight but I’ll be playing with this over the weekend for sure.  Thanks, MF =)

 Signature 
Profile
MSG
 
 
Posted: 28 September 2005 03:54 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  05-14-2004

This is definitely intriguing. I’ll have to give it a try!  Thanks. smile

 Signature 

Moxie Design Studios™ • Top Shelf Blog & Website Design by The Moxie Girls™
EE ProNetwork • (EE 1.6.5, build 20081024)

Profile
 
 
Posted: 29 September 2005 11:26 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

I�ve written an EE plugin that will let you show all ancestor categories of a given category. I call it the “Breadcrumb” plugin.

Note:

This plugin and the “Breadcrumb” Plugin are a pair.

The “breadcumb” Plugin will show the ancestor categories of a category and the “Subcategories” plugin will show the children categories of a category.

 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 30 September 2005 09:27 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  836
Joined  04-17-2002

I for one will find both of these plugins very useful as my work project involves publishing info in much the same manner as a book, where the order of the entries needs to be by category and sub-category (chapter and sub-chapter).

I can’t tell from the docs and don’t have time to test right now, but can you tell me, could I embed a weblog entries tag pair inside the sub cat plugin tags and use the category_id output to give me a correctly ordered list of entries?

something like

{exp:subcategories sort_by="category_order"}
{exp
:weblog:entries category="{category_id}"}
content
...
{/exp:weblog:entries}
{
/exp:subcategories}

That is, ordered according to category rather than title or date. In this situation, the order of entries is crucial. At the moment I do this with php but it is a bit of a hack (especially given my lack of php knowledge).

I’m not sure if you have even considered the possibilty of embedding other tags, but I can see a couple of problems trying to embed weblog entries tags. First, if there are no results, no entries will be shown for those bottom level categories. Second, your plugins and the weblog entries tags share some variable names. This might cause some conflicts if someone (eg: me) is foolish enough to try embedding.

Maybe consider an {if no_results} conditional?

Anyway, thanks for your hard work. I’ll definitely be giving both of these a try next week.

 Signature 

antipodean.org | uptheduff.org

Profile
 
 
Posted: 30 September 2005 11:43 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

@Tim

a) You’re right, I had not thought of embedding other plugin/module tags in these tags. I’m not sure what it would take to make this work. Maybe EE automatically recognizes these tags within plugins. Maybe some Pro’s can share their insights regarding this.

But if it works I would think that you could order the outcome the way you want.

You/I might try it out and see what the outcome is.

b) Regarding name conflicts, I would think that that is not a problem, since parameters and variables exist within the scope/context of their plugin/module tags. But I don’t know for sure. Maybe some Pro’s can share their insights regarding this too.

You/I might try it out and see what the outcome is.

c) Regarding the {if no_results} tag. How do you want this to work? Can you tell me more?

 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 30 September 2005 11:50 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

@Tim

Currently you could use the {if entries_count == 0} tag to check if there are no entries assigned to a category. Would this help?

 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 30 September 2005 11:55 AM   [ Ignore ]   [ # 11 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32921
Joined  05-14-2004

Variables matter.  I know that Yoshi ran into this with the linklist module a few times and had to rename things like the url and the {title} to be unique.  It happened with the magpie plugin, too, again with {title}.

 Signature 
Profile
MSG
 
 
Posted: 01 October 2005 07:20 AM   [ Ignore ]   [ # 12 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  836
Joined  04-17-2002
MF - 30 September 2005 11:50 AM

@Tim

Currently you could use the {if entries_count == 0} tag to check if there are no entries assigned to a category. Would this help?

No, I mean if there are no sub-categories, provide a means to display something. There is an {if no_results} variable pair for the weblog entries tag. Maybe you could look at that. Don’t get me wrong, I’m really looking forward to testing this plugin, I’m just considering some problems I might come across in using it in my particular application.

 Signature 

antipodean.org | uptheduff.org

Profile
 
 
Posted: 01 October 2005 09:29 AM   [ Ignore ]   [ # 13 ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

@LisaJill

Good to know. I don’t know how I want to address that…

@Tim

Thanks for explaining smile. You’re right this would be a helpful addition. I will add it soon.

@Sue

Now I know that you meant what Tim suggested smile .

 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 01 October 2005 03:37 PM   [ Ignore ]   [ # 14 ]  
Lab Assistant
RankRank
Total Posts:  102
Joined  08-28-2005

I downloaded and installed the plugin and I made a template called “categories”, but I am new at this and am having problems.

Simply put, I want the template which shows this:

Category Title
————————
List of Subcategories of that category
————————
List of Entries in this Category

or, for example:

PIES
————————
Apple Pies
Cherry Pies
Banana Pies
Cream Pies
————————
10 Ways to Cut a Pie
101 Pie Making Tips
7 Great Pie Recipies

Here is an example of what I am trying to create.

Here is my template:

{assign_variable:master_weblog_name="tech"}

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<
head>
<
title>{exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info}</title>
<
meta http-equiv="Content-Type" content="text/html; charset={charset}” />

<link rel=’stylesheet’ type=’text/css’ media=’all’ href=’{stylesheet=weblog/weblog_css}’ />
<style type=’text/css’ media=’screen’>@import “{stylesheet=weblog/weblog_css}”;</style>
</head>

<body>

<div id="
wrapper">
<div id="
header">

<div id="
blogtitle"><h1>{exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info}</h1></div>

<div id="
nav"><a href="{homepage}">Home</a> | <a href="#">About</a> | <a href="{path=weblog/archives}">Archives</a> | <a href="#">Links</a> | <a href="mailto:you@domain.com">Contact</a></div>

<div class="spacer"></div>
</
div>

<
div class="spacer"></div>
<
div id="content">


<
div id="blog">

{exp:weblog:category_heading weblog="{master_weblog_name}"}
<h1>{category_name}</h1>
{if category_description}
<p>{category_description}</p><div class="posted">Posted by <a href="{profile_path=member/index}">{author}</a> on {entry_date format=%m/%d’} at {entry_date format=%h:%i %A’}

<br />

{categories}
<a href="{path=SITE_INDEX}">{category_name}</a>
{
/categories}

{if allow_comments}
({comment_total}) <a href="{url_title_path="weblog/comments"}">Comments</a>
{
/if}

{if allow_trackbacks}
({trackback_total}) <a href="{trackback_path="weblog/trackbacks"}">Trackbacks</a>
{
/if}
<a href="{title_permalink=weblog/index}">Permalink</a>

</
div>

{paginate}

<div class="paginate">

<
span class="pagecount">Page {current_page} of {total_pages} pages</span> {pagination_links}

</div>

{/paginate}

{
/exp:weblog:entries}

</div>

<
div id="sidebar">

</
div>
</
div>
<
br class="spacer" />
<
div id="footer">

</
div>
</
div>
</
body>
</
html>

What would I add to this template to have it show a list of subcategories for the category?

Profile
 
 
Posted: 01 October 2005 03:47 PM   [ Ignore ]   [ # 15 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9868
Joined  06-19-2002

You’re missing the closing {/exp:weblog:category_heading} tag and the opening {exp:weblog:entries} tag.  Between those two, you should place the code for the new plugin.

 Signature 

Chris Curtis
chriscurtis.org

Profile
 
 
Posted: 01 October 2005 03:50 PM   [ Ignore ]   [ # 16 ]  
Lab Assistant
RankRank
Total Posts:  102
Joined  08-28-2005

The problem is that it only displays the top level categories. I have my Categories like this:

-Topics
-Regions
    -Africa
        -Zimbabwe

It should display Zimbabwe, however it is displaying “Topics” and “Regions”

Here is my page:

http://www.technologyandchange.com/1/home/nav/topic/Africa/

Here is a new template:

{assign_variable:master_weblog_name="tech"}
<?xml version
="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>{exp:weblog:info weblog="{master_weblog_name}"}{blog_title}{/exp:weblog:info}</title>
<
style type='text/css' media='screen'>@import "{stylesheet=home/index-style}";</style>
<
style type='text/css' media='screen'>@import "{stylesheet=global/headfoot-style}";</style>
</
head>
<
body>
<
div id="container">
{embed="global/header"}

<div id="nav">

</
div>

<
div id="content">
<
div id="nav-menu">
<
div id="title-box"><h2>Topics</h2></div>
<
table id="nav-menu-table">
{exp:subcategories}
<li>{category_name}</li>
{/exp:subcategories}
</table>
</
div>

<
div class="ad-box-2"></div>

<
div>
<
div id="title-box"><h2>Recent Articles</h2></div>
{exp:weblog:entries weblog="{master_weblog_name}" orderby="date" sort="desc" limit="15"}
<div class="post">
<
div class="post-title"><h3><a href="{title_permalink=articles/view/index}">{title}</a></h3></div>
<
div class="post-details">By <span class="strong">{author}</span> on {entry_date format='%m/%d'}</div>
<
div class="post-summary">{summary}</div>
<
div class="post-options"><a href="{title_permalink=articles/view/index}" class="strong">Read More...</a></div>
</
div>
{/exp:weblog:entries}
</div>

</
div>
{embed="global/footer"}
</div>
</
body>
</
html>

Profile
 
 
Posted: 02 October 2005 02:18 AM   [ Ignore ]   [ # 17 ]  
Research Assistant
RankRankRank
Total Posts:  761
Joined  06-01-2004

Hi livenomadic

Regarding your wish to show the following:

a) Category Title
b) List of Subcategories of that category
c) List of Entries in this (current) category

Use a category that is passed to the template through the url and then place these tags in your template:

a) Use

{exp:weblog:category_heading}
{category_name}
{/exp:weblog:category_heading}

b) Use

{exp:subcategories ...}
{category_name}
{/exp:subcategories}

c) Use

{exp:weblog:entries ...}
{title}
{/exp:weblog:entries}

Also… How are your categories structured? With subcategories such as:

Topics
—-Regions
———Africa
————-Zimbabwe
————-Nigeria
———Europe
————-France
————-Germany

...or are they all on the same level?


(BTW… regarding your HTML code around the {exp:subcategories tag}. It would make more sense to use the “unordered list” tag <ul> in conjunction with <li> list items tag.>)


And…Here’s one example of how I use the plugin:

<style type="text/css">
<!--
.
hide {
display
: none;
}
.subcategories {
clear
: both;
margin: 0;
padding: 15px 0 0 0;
width: 728px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
img {
border
: none;
}
.subcategories h2 {
margin
: 0;
padding: 3px 0 0 0;
font-size: 12px;
font-weight: bold;
color: #333;
/*border-top: 1px dashed #807cab;*/
background-image: url(/images/de-layout-basics-2/muster_2.png);
background-position: top;
background-repeat: repeat-x;
}
.subcategories ul {
float
: left;
width: 728px;
margin: 0;
padding: 10px 0 0 0;
list-
style-type: none;
}
.subcategories ul li {
float
: left;
width: 182px;
margin: 0;
padding: 0;
line-height: 1.618em;
font-size: 10px;
}
.subcategories li a {
color
: #0033cc;
}
-->
</
style>

<
div class="subcategories">
  <
h2>Kategorien</h2>
  <
ul>
     
{exp:subcategories sort_by="category_name" count_entries_from_weblogs="22" count_entries_with_status="open|closed"}
    
<li><a href="{template_path=templategroup/template}">{category_name} {if entries_count > 0}({entries_count}){/if}</a></li>
    
{/exp:subcategories}
  
</ul>
</
div>

 Signature 

mode.com | schmuck.com | mode.ch | shop.ch

Profile
 
 
Posted: 02 October 2005 07:00 AM   [ Ignore ]   [ # 18 ]  
Lab Assistant
RankRank
Total Posts:  102
Joined  08-28-2005

When I paste:

{exp:subcategories}
{category_name}
{/exp:subcategories}

I am getting the wrong categories displayed.

The subcategories of:

http://www.technologyandchange.com/1/home/nav/topic/Africa/

is “Zimbabwe”

But as you can see it is displaying the categories “Regions” and “Topics”

Profile
 
 
   
1 of 6
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65074 Total Logged-in Users: 23
Total Topics: 82207 Total Anonymous Users: 13
Total Replies: 441811 Total Guests: 187
Total Posts: 524018    
Members ( View Memberlist )
Newest Members:  mackskithbtggAdminempoleongwishPasha MahardikarmarkdurandomcatClutch BearingsAdil