如果我理解正确,这是正确的做法, 首先,你需要在Word中创建按管理菜单空白菜单菜单。现在去函数.php文件(主题文件)中添加下面的代码。
你可以得到产品cateogorty名单从这个功能,
function get_product_terms($term_id) {
$html = '';
$args = array('hide_empty' => 0, 'parent' => $term_id);
$terms = get_terms('product_cat', $args);
foreach ($terms as $term) {
$html .= '<li';
if($term_id == 0) {
$html .= ' class="top_li"';
}
$html .= '><a href="'.get_term_link($term->slug, 'product_cat').'">' . $term->name . '</a>';
if($list = get_product_terms($term->term_id)) {
$html .= '<ul class="second_level">'.$list.'</ul>';
}
$html .= '</li>';
}
return $html;
}
您可以使用此功能添加产品类别菜单,
// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items) {
// Woo function
/*//product_cat
$terms = get_terms('product_cat', $args);
print_r($terms);*/
if($list = get_product_terms(0)) {
$menu1link = '<li class="home"><a href="' . home_url('/') . '">' . __($list) . '</a></li>';
$homelink = '<li class="home"><a href="' . home_url('/') . '">' . __('Home') . '</a></li>';
// add the home link to the end of the menu
$items = $items . $homelink;
$items = $items .$menu1link;
}
return $items;
}
add_filter('wp_nav_menu_items', 'new_nav_menu_items');
第二功能为产品类别的菜单写入.' $ list'具有您想要的所有类别 –
我已经为它创建了自定义帖子类型”产品“和分类为”产品类别“使用类型插件。然后,我使用类别图像插件在分类中添加了“产品类别”和类别图像中的类别名称组。我知道如何在wordpress中显示其图像和类别名称? – anumol