【发布时间】:2016-08-28 12:15:14
【问题描述】:
如何将活动类添加到 wordpress:<?php wp_get_archives('type=yearly'); ?> 生成的输出。
【问题讨论】:
如何将活动类添加到 wordpress:<?php wp_get_archives('type=yearly'); ?> 生成的输出。
【问题讨论】:
您可以按照以下步骤添加 CSS 选择器:
第 1 步:
将以下函数放入您的functions.php
function wpse_62509_current_month_selector( $link_html ) {
$current_month = date("F Y");
if ( preg_match('/'.$current_month.'/i', $link_html ) )
$link_html = preg_replace('/<li>/i', '<li class="current-month">', $link_html );
return $link_html;
}
然后在调用wp_get_archives()之前添加以下行
add_filter( 'get_archives_link', 'wpse_62509_current_month_selector' );
您可能还想在调用 wp_get_archives() 后删除过滤器,以免与其他 wp_get_archives() 或 get_archives_link() 函数调用混淆。
remove_filter( 'get_archives_link', 'wpse_62509_current_month_selector' );
这将创建当前月份的 CSS 选择器。希望这会对您有所帮助。
【讨论】: