Category breadcrumb + subcategories on cat listing
Posted: 09 June 2005 10:57 AM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  361
Joined  2003-11-19

I didn’t find any way to do this in the docs, so I came up with a SQL query.

If you go to a specific category, there is no way to display a bread crumb menu with all its parent categories. It’s only possible to do so in a weblog entry, not on the category listing pages. The following code makes it possible.

Also, the following code gives a listing of all the subcategories.

=======================================

{exp:weblog:category_heading}
<a href="####home">HOME</a>{exp:query sql="SELECT exp_categories.cat_id, exp_categories.parent_id, exp_categories_1.cat_name AS c1, exp_categories_2.cat_name AS c2, exp_categories_3.cat_name AS c3, exp_categories_4.cat_name AS c4, exp_categories_1.cat_id AS i1, exp_categories_2.cat_id AS i2, exp_categories_3.cat_id AS i3, exp_categories_4.cat_id AS i4
FROM (((exp_categories INNER JOIN exp_categories AS exp_categories_1 ON exp_categories.parent_id = exp_categories_1.cat_id) LEFT JOIN exp_categories AS exp_categories_2 ON exp_categories_1.parent_id = exp_categories_2.cat_id) LEFT JOIN exp_categories AS exp_categories_3 ON exp_categories_2.parent_id = exp_categories_3.cat_id) LEFT JOIN exp_categories AS exp_categories_4 ON exp_categories_3.parent_id = exp_categories_4.cat_id
WHERE (((exp_categories.cat_id)={category_id}));
“}
{if c4 !=""} > <a href="###site.com####/categories/C{i4}/">{c4}</a>{/if}
{if c3 !=""} > <a href="###site.com####/categories/C{i3}/">{c3}</a>{/if}
{if c2 !=""} > <a href="###site.com####/categories/C{i2}/">{c2}</a>{/if}
{if c1 !=""} > <a href="###site.com####/categories/C{i1}/">{c1}</a>{/if}
{/exp:query} > {category_name}
<br>
<br>

{exp:query sql="SELECT exp_categories.cat_id, exp_categories.cat_name, exp_categories.group_id, exp_categories.parent_id, count( exp_category_posts.entry_id ) AS count, exp_categories.parent_id
FROM exp_categories LEFT JOIN exp_category_posts ON exp_categories.cat_id = exp_category_posts.cat_id
GROUP BY exp_categories.cat_name, exp_categories.group_id, exp_categories.parent_id
HAVING (((exp_categories.parent_id)=’{category_id}’))
ORDER BY exp_categories.cat_name;"}

         ###site.com###/cp_images/cat_marker.gif<a href="###site.com/categories/C{cat_id}/">{cat_name} ({count})</a><br>
{/exp:query}

{/exp:weblog:category_heading}

=======================================

I’m changing the design of my website. The design is not finished and most of the new features and menus don’t work yet. However, you can view example of the above code on the following pages ;

Category without subcategories
Category with subcategories

Profile
 
 
Posted: 09 June 2005 11:00 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  30061
Joined  2004-05-14

I hope that you’ll consider adding this to the wiki
. =)

 Signature 
Profile
 
 
Posted: 14 May 2008 08:15 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  131
Joined  2006-08-14

This looks like what I am looking for. But I don’t know that type of code, so I just copied it into my template that is embedded in another template. But it gives the following error:

MySQL ERROR:

Error Number: 1064

Description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘€™4’)) ORDER BY exp_categories.cat_name’ at line 1

Query: SELECT exp_categories.cat_id, exp_categories.cat_name, exp_categories.group_id, exp_categories.parent_id, count( exp_category_posts.entry_id ) AS count, exp_categories.parent_id FROM exp_categories LEFT JOIN exp_category_posts ON exp_categories.cat_id = exp_category_posts.cat_id GROUP BY exp_categories.cat_name, exp_categories.group_id, exp_categories.parent_id HAVING (((exp_categories.parent_id)=’4’)) ORDER BY exp_categories.cat_name;

Do you know how come?

Thanks!

Profile
 
 
Posted: 14 May 2008 08:29 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11077
Joined  2004-05-15

Looks like fancy quotes and encoding issues, combined. Try to get rid of the curly quotes in exp_categories.parent_id.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.
No PM’s, please—use regular mail.

Profile
 
 
Posted: 14 May 2008 08:36 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  131
Joined  2006-08-14

Yep! That did it! Thanks a lot!

Profile
 
 
Posted: 16 May 2008 04:03 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  131
Joined  2006-08-14

Hmmm, is there a way to pull out custom entry field data? I have a multi language website that I am working on and the category names have a custom field for every language.

Profile
 
 
   
 
 
‹‹ OT...Have Fun!      templates and weblogs ››
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 10:33 AM
Total Registered Members: 58134 Total Logged-in Users: 25
Total Topics: 68142 Total Anonymous Users: 11
Total Replies: 366992 Total Guests: 429
Total Posts: 435134    
Members ( View Memberlist )
Newest Members:  Doug LernerATATJacob SmithalixJonathon VSgoodbergerDelia RitherdonbborunXofzainabob