diff --git a/README.textile b/README.textile index 249f4f0..b38526a 100644 --- a/README.textile +++ b/README.textile @@ -66,6 +66,10 @@ To get the category ID for a channel:entries tag, make sure to parse inward and @{exp:channel:entries channel="news" category="{exp:freebie:category_id segment='2'}" parse="inward"}@ +Also, when using {exp:freebie:category_id}, you can pass the optional parameters fallback="yes" and fallback_id="{category_id}" that will default entries to that category_id if freebie can't return to any entry matched by the segment parameter. Example: + +@{exp:freebie:category_id segment="3" fallback="yes" fallback_id="1"}@ + h3. A few more {freebie_last} will get you the last segment from the original URI. diff --git a/third_party/freebie/pi.freebie.php b/third_party/freebie/pi.freebie.php index 78a8613..1f2546c 100755 --- a/third_party/freebie/pi.freebie.php +++ b/third_party/freebie/pi.freebie.php @@ -89,7 +89,17 @@ function category_name() function category_id() { - return $this->category_match('cat_id'); + $match = $this->category_match('cat_id'); + + $fallback = $this->EE->TMPL->fetch_param('fallback'); + $fallback_id = $this->EE->TMPL->fetch_param('fallback_id'); + + if ( strtolower($fallback) == "yes") { + $match = $match ? $match : $fallback_id; + } + + return $match; + } function category_description()