Created
October 12, 2009 16:42
-
-
Save mrkurt/208535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
public static function get_primary_entries($category, $limit = 20){ | |
$entries = false; | |
if($category->primary_entries && count($category->primary_entries) >= $limit){ | |
$entries = $category->primary_entries; | |
} | |
if(!$entries){ | |
$used = array(); | |
$entries = array(); | |
$archive = $category; | |
do{ | |
foreach($archive->entries->load() as $entry){ | |
#echo("<h1>Checking " . $entry->url . " for " . $category->url . "</h1>"); | |
if(strpos($entry->url, $category->url) === 0 && !array_key_exists($entry->url, $used)){ | |
$used[$entry->url] = $entry; | |
$entries[] = $entry; | |
} | |
} | |
$archive = data::get_next_container($archive); | |
}while($archive && $archive->entries && count($entries) < $limit); | |
} | |
if(count($entries) > $limit){ | |
return array_slice($entries, 0, $limit); | |
}else{ | |
return $entries; | |
} | |
} | |
public static function get_next_container($container){ | |
$next = false; | |
$last_entry = false; | |
if($container->type == 'Category'){ | |
$entries = $container->entries->load(); | |
$last_entry = $entries[count($entries) - 1]; | |
$next_url = $container->url . date('Y/m/d', $last_entry->date); | |
$next = data::get_resource($next_url); | |
if(!$next) return false; | |
if($last_entry->url == $next->entries[count($next->entries) - 1]->url){ | |
$next = $next->next; | |
$last_entry = false; | |
} | |
}else if($container->type == 'Category-Daily'){ | |
$next = $container->next; | |
} | |
return $next; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment