Skip to content

Commit

Permalink
ref #516 -- fixed links not working when permalinks not set; created …
Browse files Browse the repository at this point in the history
…test for daily archives
  • Loading branch information
jarednova committed Apr 11, 2015
1 parent 3b96295 commit 4f5b591
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/timber-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,20 @@ function get_items($args = null) {
'order' => 'DESC',
'post_type' => 'post',
'show_year' => false,
'nested' => false
);

$args = wp_parse_args($args, $defaults);
$post_type = $args['post_type'];
$order = $args['order'];
$nested = $args['nested'];
$type = $args['type'];
$limit = '';
$nested = true;
if ($type == 'monthly' || $type == 'yearly') {
$nested = false;
if ( $type == 'yearlymonthly' || $type == 'yearmonth' ) {
$type = 'monthly-nested';
}
if ( $type == 'monthly-nested' ) {
$nested = true;
}
$before = $args['before'];
$after = $args['after'];
Expand Down Expand Up @@ -186,7 +190,7 @@ function get_items($args = null) {
$output = $this->get_items_montly($args, $last_changed, $join, $where, $order, $limit, $nested);
} elseif ('yearly' == $type) {
$output = $this->get_items_yearly($args, $last_changed, $join, $where, $order, $limit);
} elseif ('yearlymonthly' == $type || 'yearmonth' == $type || 'monthly-nested') {
} elseif ('monthly-nested' == $type) {
$years = $this->get_items_yearly($args, $last_changed, $join, $where, $order, $limit);
foreach ($years as &$year) {
$args = array('show_year' => false);
Expand Down
12 changes: 9 additions & 3 deletions lib/timber-url-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function get_rel_url($url, $force = false) {
return $url;
}
$link = '';
if (isset($url_info['path'])){
if (isset($url_info['path'])){
$link = $url_info['path'];
}
if (isset($url_info['query']) && strlen($url_info['query'])) {
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function get_full_path($src) {

/**
* Takes a url and figures out its place based in the file system based on path
* NOTE: Not fool-proof, makes a lot of assumptions about the file path
* NOTE: Not fool-proof, makes a lot of assumptions about the file path
* matching the URL path
* @param string $url
* @return string
Expand Down Expand Up @@ -148,6 +148,12 @@ public static function prepend_to_url($url, $path) {
if (strstr(strtolower($url), 'http')) {
$url_parts = parse_url($url);
$url = $url_parts['scheme'] . '://' . $url_parts['host'] . $path . $url_parts['path'];
if ( isset($url_parts['query']) ) {
$url .= $url_parts['query'];
}
if ( isset($url_parts['fragment']) ) {
$url .= $url_parts['fragment'];
}
} else {
$url = $url . $path;
}
Expand Down Expand Up @@ -175,7 +181,7 @@ public static function is_absolute($path) {
/**
* @param string $url
* @return bool true if $path is an external url, false if relative or local.
* true if it's a subdomain (http://cdn.example.org = true)
* true if it's a subdomain (http://cdn.example.org = true)
*/
public static function is_external($url) {
$has_http = strstr(strtolower($url), 'http');
Expand Down
11 changes: 11 additions & 0 deletions tests/test-timber-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ function testArchiveYearly(){
$this->assertEquals(3, count($archives->items));
}

function testArchiveDaily(){
$dates = array('2013-11-08', '2013-12-08', '2013-11-09', '2013-11-09', '2013-06-08', '2014-01-08'
);
foreach( $dates as $date ) {
$this->factory->post->create(array('post_date' => $date.' 19:46:41'));
}
$this->go_to('/');
$archives = new TimberArchives(array('type' => 'daily'));
$this->assertEquals(5, count($archives->items));
}

function testArchiveYearlyMonthly(){
$dates = array('2013-11-08', '2013-12-08', '2013-11-09', '2013-06-08', '2014-01-08'
);
Expand Down

0 comments on commit 4f5b591

Please sign in to comment.