Thank you MF for a nice and nifty plugin.
In case anyone is interested, I have made a slight modification to MF’s plugin to support getting the ancestor categories (ie. the breadcrumbs) using category names instead of category IDs. This might be useful for those who prefer to use category names in their URLs rather than IDs.
This does assume that to operate correctly, you use unique category names in your categories within EE (however, if you are using names in the URLs, then you probably already have enforced unique names in your categories anyway).
e.g. usage of the modified version of the plugin would be:
In this example, what’s going on is:
1) the category name (root_node_name in the parameter list to be consistent with naming of params that MF used) comes from “segment_3” of the URL. adjust this to whatever is suitable for how your site is set up
2) “best practice” is not to have spaces in your URLs, so we set up all our category names with “_” for spaces. So in the above, we are replacing the underscores with spaces before displaying the text to users. This requires you to install the “Find and Replace” plugin from Lodewijk Schutte, which you can find elsewhere on the forums.
3) The breadcrumbs are formatted to give a final display like this “Category > Parent > First Child > Second Child > Third Child > etc…”
As far as I know, the modifications have not broken any of the original functionality of the plugin. That said, the modifications are not the most robust possible and do assume that you will put in valid text into the root_node_name param. If you put in some invalid text, you may get unexpected results. For us, we have found the modified version to work well enough to use in production without any issues.
Hope this is of use to some of you.
I cant get this to work, nothing shows when I have this:
{exp:breadcrumb root_node="10" sort_direction="desc"}
<li>{category_name}</li>
{/exp:breadcrumb}
10 is my category id for my paintings category…And I have renamed the plugin to pi.breadcrumb.php
Im on EE 1.5.2. Is it compatible with the plugin?
thanks!
Ok you might laugh at myt ott code, but I’m just stoked i got unlimited menu heirarchy of pages, nav highlighting and breadcrumbs from a signle template without using the pages module! Only this plugin was required and the 1.6EE…
Prerequirements are:
1) the breadcrumb plugin 2) ‘Use Category URL Titles In Links?’ set to yes, (note in the example below i’ve used section as my ‘category url indicator’) 3) You’ll also need to allow php on your template. 4) A weblog called Pages 5) A category group that relates to your site structure 6) Auto select category parents should be off 7) A single entry into each of your pages categories (page content)
Screenshot of the output attached.
Heres my nasty code that someones bound to improve on:
<!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=utf-8" />
<title>Test</title>
{!-- Nav Highlighting --}
<style type="text/css">
<!--
li a.{segment_2} {color: red;}
-->
</style>
</head>
<body>
{!-- Query to establish current node for breadcrumb plugin --}
{exp:query sql="SELECT cat_url_title AS caturltitle, cat_id, cat_name FROM exp_categories WHERE cat_url_title = '{segment_2}' "}
{!-- Begin Breadcrumbs --}
<a href="http://{path=/}">Home</a> >
{exp:breadcrumb root_node="{cat_id}"}
{!-- Open the link and begin the hack --}
<a href="http://10.1.1.3/ee1-6/index.php/section/{%21--">{!-- Close the link --}__{category_name}__</a> > {/exp:breadcrumb}
{/exp:query}
{exp:weblog:entries limit="1" weblog="pages"}
{title}
{!-- End Breadcrumbs --}
{!-- Content--}
<h1>{title}</h1>
{content}
{/exp:weblog:entries}
{!-- Menu--}
{exp:weblog:categories weblog="pages" show_empty="no"}<a href="http://{path=/}" class="{category_url_title}">{category_name}</a>{/exp:weblog:categories}
</body>
</html>
Hi all,
I’ve a problem with MF’s subcategories plugin.
{exp:subcategories root_node="{embed:category}" sort_by="custom_order"}
<li><a href="http://{path=products/list}">{category_name}</a></li>
{/exp:subcategories}
This code list subcategories correctly, but my problem is with links. Because isn’t like categories tag, with this code, the dynamic path won’t work.. and every link goes to products/list.
¿How can fix it to take dynamic url, like categories tag?
Thanks all,
Ok: I am posting what I posted in the How To section Sue Crocker pulled code for me to sort selectively display categories and display them in the right column. There is a bug in it when I limit the number of entries displayed let’s say to 5 and then the blog paginates. when you click on the second page of entries the category sorter does not work.
Here is when it works fine without page pagination (although when logged it as admin I get this error: Notice: Undefined variable: cat_name in /home/pmh2640/public_html/murmann/system/core/core.functions.php(637) : eval()‘d code on line 117)
http://professor-murmann.info/index.php/weblog/courses/
Here is a copy with the big bug. I already put in on the second page of entries so that you can see it readily. http://professor-murmann.info/index.php/weblog/courses_bug/P5/
This is the code that Sue installed. She says it is from someone called MF in Germany. Can you help?
**********Code*******************************
There are a some posts in this thread from people saying the plugin doesn’t work, but I managed to get it working fine in EE 1.6.9 build 20100430. I’m adding to this thread to show people how to add category URL functionality, since this plugin does not natively support it.
First of all, the plugin does not seem to work inside of the category heading tag pair, so I had to move the plugin code to an embed template and pass in the category ID:
Main template:
{exp:weblog:category_heading weblog="products"}
{embed="embeds/breadcrumb" cat_id='{category_id}'}
{category_name}
{/exp:weblog:category_heading}
Embedded breadcrumb template:
{exp:breadcrumb root_node="{embed:cat_id}"}
{category_name} ›
{/exp:breadcrumb}
This created a nice breadcrumb trail, but none of the ancestor categories were linked. To do this, I had to make an adjustment and an addition to the plugin file:
Tell the plugin to grab URL info (around line 218):
$sql = "SELECT cat_id, ***cat_url_title***, parent_id, cat_name, cat_image, cat_description, cat_order FROM exp_categories WHERE cat_id = ...
The cat_url_title piece (surrounded by asterisks) is not there; I added it so the query grabs the URL for each category.
Next, add a new variable (copy + paste the following somewhere near line 232):
//parse category_url_title variable
if ($key == 'category_url') {
if (isset($query->row['cat_url_title'])) {
$tagdata = $TMPL->swap_var_single($val, $query->row['cat_url_title'], $tagdata);
}
}
Lastly, in your embed template, add a link with the new {category_url} variable, and you’re in business:
{exp:breadcrumb root_node="{embed:cat_id}"}
<a href="http://{site_url}category/{category_url}">{category_name}</a> ›
{/exp:breadcrumb}
Thanks to MF for this really helpful plugin. I looked everywhere and this is THE best way to do category breadcrumbs.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.