利用$wpdb自定义查问能够调用某年下的月份归档, 例如调用2014年月份归档的代码如下所示。
// Get archive by year
global $wpdb, $wp_locale;
$year = 2014;
$query = "SELECT DISTINCT MONTH(post_date) AS `month` FROM $wpdb->posts WHERE `post_type` = 'post' AND `post_status` = 'publish' AND YEAR(post_date) = $year ORDER BY `month` DESC";
$months = $wpdb->get_results($query);
echo '<ul>';
echo '<li><a href="'.get_year_link( $year ).'">'.sprintf('%d', $year).'</a>';
echo '<ul class="month-list">';
foreach( $months as $month ) {
$text = sprintf(__('%1$s'), $wp_locale->get_month($month->month));
echo '<li><a href="'.get_month_link( $year, $month->month).'">'.$text.'</a></li>';
}
echo '</ul></li></ul>';
输入如下:
<ul>
<li><a href="http://yourdomain.com/2013/">2013</a>
<ul class="month-list">
<li><a href="http://yourdomain.com/2013/11/">十一月</a></li>
<li><a href="http://yourdomain.com/2013/09/">九月</a></li>
<li><a href="http://yourdomain.com/2013/08/">八月</a></li>
<li><a href="http://yourdomain.com/2013/06/">六月</a></li>
<li><a href="http://yourdomain.com/2013/02/">二月</a></li>
</ul>
</li>
</ul>
以上就是安达网络工作室关于《WordPress查询某年某月文章的SQL语句》的一些看法。更多内容请查看本栏目更多内容!
本文实例讲述了获取wordpress注册用户的数量的办法分享给大家供大家参考。详细完成办法如下: 办法一,代码如...
明天在修正网站的时分,不小心把最新版Wordpress3.5.1的wp-includes目录下的functions.php笼罩出来了,招致...
本文实例讲述了wordpress首页不显示指定分类文章的办法。分享给大家供大家参考。详细剖析如下: 有时咱们不...
get_template_part() 用来援用模板文件,相似于 get_header()、get_sidebar() 和 get_footer(),只不过这个...
对搜寻引擎暗藏特定的文章 这个成绩的起源是这样的: 家喻户晓,随着搜寻引擎的改进,会越来越排挤采集和伪...
七牛云存储是由七牛提供的在线存储效劳,经过云端接口向企业客户提供网上有限存储空间,和传统的云存储效劳...