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.
- There is a limit of 5 categories in the breadcrumb menu. You’ll need to edit the query if you need more.
- The code needs to be inserted in category_heading tag as shown above. Hence, it will not work on pages where the category_heading tag doesn’t work.
- It should work as is. Just copy and paste it in your template and it should work. You’ll only need to change the various URLS where you see ####.
- The cat_marker.gif is the same image used in the EE control panel for lists of categories. Just make the tag point to the proper location on your server. Obviously, you can get rid of it if you want ...
{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;"}
<img src="###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}
