Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Category fallback #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion third_party/freebie/pi.freebie.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down