From 7e9df8bc478bde41ef1acc350d6597916216594b Mon Sep 17 00:00:00 2001 From: Rodrigo Passos Date: Fri, 4 Apr 2014 19:12:42 -0400 Subject: [PATCH 1/2] implemented category fallback option --- third_party/freebie/pi.freebie.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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() From 56bf07bec3d31504d6b065db8a30a8438e3e7cbf Mon Sep 17 00:00:00 2001 From: Rodrigo Passos Date: Fri, 4 Apr 2014 19:12:58 -0400 Subject: [PATCH 2/2] updated Docs with fallback feature --- README.textile | 4 ++++ 1 file changed, 4 insertions(+) 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.