Skip to content

Instantly share code, notes, and snippets.

@akiya64
Created April 17, 2016 04:12
Show Gist options
  • Select an option

  • Save akiya64/e19bea2a383ae7da0aad83bfdce6fc61 to your computer and use it in GitHub Desktop.

Select an option

Save akiya64/e19bea2a383ae7da0aad83bfdce6fc61 to your computer and use it in GitHub Desktop.
shirohanada
<?php if(is_month()){
//Previous - Next Month Nav//
$before_post_month = strtotime(get_the_time('Y-m')." -1 month");
$before_month = array (
"year" => date('Y', $before_post_month),
"month" => date('m', $before_post_month),
);
$before_month_link = get_month_link($before_month['year'], $before_month['month']);
$after_post_month = strtotime(get_the_time('Y-m')." +1 month");
$after_month = array (
"year" => date('Y', $after_post_month),
"month" => date('m', $after_post_month),
);
$after_month_link = get_month_link($after_month['year'], $after_month['month']);
echo '<a href="'.$before_month_link.'"><i class="icon icon-angle-left"></i>Older '.date('Y.m', $before_post_month).'</a>';
echo '<a href="'.$after_month_link.'">'.date('Y.m', $after_post_month).'Newer <i class="icon icon-angle-right"></i></a>';
}elseif(is_date()){
//Previous - Next Month Nav
$before_post_day = strtotime(get_the_time('Y-m-d')." -1 day");
$before_day = array (
"year" => date('Y', $before_post_day),
"month" => date('m', $before_post_day),
"day" => date('d', $before_post_day),
);
$before_day_link = get_day_link($before_day['year'], $before_day['month'], $before_day['day']);
$after_post_day = strtotime(get_the_time('Y-m-d')." +1 day");
$after_day = array (
"year" => date('Y', $after_post_day),
"month" => date('m', $after_post_day),
"day" => date('d', $after_post_day),
);
$after_day_link = get_day_link($after_day['year'], $after_day['month'], $after_day['day']);
echo '<a href="'.$before_day_link.'" class="previous-day"><i class="icon icon-angle-left"></i>'.date('Y.m.d', $before_post_day).'</a>';
echo '<a href="'.$after_day_link.'" class="next-day">'.date('Y.m.d', $after_post_day).'<i class="icon icon-angle-right"></i></a>';
}else{
echo '<a href="'.get_month_link('', '').'">Recent Posts</a>';
}
?>
@akiya64
Copy link
Author

akiya64 commented Apr 17, 2016

WordPress method exists, rewrite this.

<nav class="move-date">
    <a href="<?php previous_posts_link(); ?>"><i class="icon icon-angle-left"></i>Older Posts</a>
    <a href="<?php next_posts_link(); ?>">Newer Posts<i class="icon icon-angle-right"></i></a>
</nav>

@akiya64
Copy link
Author

akiya64 commented Apr 17, 2016

リンクテキストに日付を表示したい、などには使い回せると思う。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment