目前在我的wordpress网站上,我在主页上的小部件中设置了档案。 Wordpress会按月自动分离存档。而不是这样做,我希望它能在一年之间分开,但不是在一月份将年份分开,我希望它能成为八月份。
例如,我希望它以这种风格分开(它在一个下拉/ html选择菜单中):
2014-2015
-August 2014
-September 2014
...
-December 2014
-January 2015
...
- June 2015
- July 2015
2013-2014
-August 2013
我一直在互联网上寻找看似永远的东西,甚至找不到任何东西。
我认为可以使用wordpress的mysql来完成,到目前为止,我有这个(大部分)按年分隔它:
$years = $wpdb->get_results("SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY year DESC");
foreach ( $years as $year ) {
$posts_this_year = $wpdb->get_results( "SELECT ID, post_title FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' AND YEAR(post_date) = '" . $year->year . "'" );
echo '<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">';
echo '<option selected disabled>' . $year->year . '</option>';
foreach ( $posts_this_year as $post ) {
echo '<option value="' . get_permalink($post->ID) . '">' . $post->post_title . '</option>';
}
echo '</select>';
}
但我不能让sql每隔8月份而不是每年1月分开它。
任何帮助将不胜感激! :)
答案 0 :(得分:-1)
我现在无法测试,但这应该可以解决问题:
...
foreach ( $years as $year ) {
$posts_this_year = $wpdb->get_results("
SELECT
ID,
post_title
FROM wp_posts
WHERE
post_type = 'post'
AND post_status = 'publish'
AND YEAR(post_date - INTERVAL 7 MONTH) = '" . $year->year . "'"
);
...