アーカイブページに前の月/次の月のリンク追加
-
お世話になります
アーカイブページ(archive.php)に、前の月と次の月のリンクを追加したいのですが
良い方法が見つけられません。
何か良い方法はありませんか?よろしくお願いします。
5件の返信を表示中 - 1 - 5件目 (全5件中)
-
こんにちは
<?php get_month_link( $year, $month ); ?>
http://codex.wordpress.org/Function_Reference/get_month_link
参考になればうれしいです
masatoshigotoさん、nobitaさん
前後の月に投稿があるとは限らないので、get_calendarをechoせずに、得られたhtmlソースを正規表現にかけてリンクを抜き出すのが、比較的お手軽かと思います。
こんにちは、
私が配布している Raindropsというテーマ用に、prev next navigationの関数を書いたので、参考になればうれしいです。
万一使ってくれる場合は、Raindrops テーマの GPLライセンスになりまーすのでよろしくお願いします。
functions.php
function raindrops_monthly_archive_prev_next_navigation(){ global $wpdb, $wp_query; if( is_month() ){ if ( have_posts() ) { $thisyear = mysql2date('Y', $wp_query->posts[0]->post_date); $thismonth = mysql2date('m', $wp_query->posts[0]->post_date); }else{ return; } $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); $last_day = date('t', $unixmonth); $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC LIMIT 1"); $html = '<a href="%1$s" class="%3$s">%2$s</a>'; if ( $previous ) { $calendar_output = sprintf( $html, get_month_link($previous->year, $previous->month) , sprintf(__('%sth','Raindrops'), $previous->month), 'alignleft' ); } $calendar_output .= "\t" ; if ( $next ) { $calendar_output .= sprintf($html, get_month_link($next->year, $next->month), sprintf(__('%sth','Raindrops'), $next->month), 'alignright' ); } $html = '<div class="%1$s">%2$s</div>'; $calendar_output = sprintf( $html, 'raindrops_monthly_archive_prev_next_navigation', $calendar_output ); echo apply_filters( 'raindrops_monthly_archive_prev_next_navigation', $calendar_output ); } }
templatefile( Raindropsでは、date.phpに入れます )
<?php raindrops_monthly_archive_prev_next_navigation(); ?>
jim912さんおすすめの方法も試したので、
preg_match('!<tfoot>(.*)<\/tfoot>!siu',get_calendar(true, false), $regs ) ; echo "<table>{$regs[1]}</table>";
2行で終わりますね すごく簡単ですね
nobitaさん、jim912さん
親切な対応ありがとうございます。
上記方法で解決いたしました!
5件の返信を表示中 - 1 - 5件目 (全5件中)
- トピック「アーカイブページに前の月/次の月のリンク追加」には新たに返信することはできません。