【发布时间】:2018-08-22 04:02:21
【问题描述】:
我有一个像这样打印出来的产品类别导航菜单
<?php
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
);
$product_categories = get_terms( 'product_cat', $cat_args );
if( !empty($product_categories) ){
echo '<ul>';
foreach ($product_categories as $key => $category) {
echo '<li class="menuNav">';
echo '<a href="/'.$category->slug.'_product_sale/" >';
echo get_term_meta($category->term_id, 'cat_one', true);
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
?>
现在我想比较它们的 href 属性和当前页面的 slug,如果它们匹配,我想给那个锚标记一个类名'current'。 这样我就可以设置一个锚标记的样式以显示当前选择了哪个类别。
我发现我可以像这样抓取当前页面的 slug
$current_page_slug = $post->post_name;
我不知道如何一一抓取href属性并与slug进行比较。 我能得到任何帮助吗?
【问题讨论】:
标签: php wordpress woocommerce custom-taxonomy