如何将active类添加到wordpress:<?php wp_get_archives('type=yearly'); ?>生成的输出。
发布于 2016-08-28 14:48:30
您可以按照以下步骤添加如下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选择器用于当前月份。希望这会对你有帮助。
https://stackoverflow.com/questions/39191164
复制相似问题